Skip to content

Commit 815703e

Browse files
arndbbp3tk0v
authored andcommitted
EDAC/mem_repair: Reduce stack usage in edac_mem_repair_get_desc()
Constructing an array on the stack adds complexity and can exceed the warning limit for per-function stack usage: drivers/edac/mem_repair.c:361:5: error: stack frame size (1296) exceeds limit (1280) in 'edac_mem_repair_get_desc' [-Werror,-Wframe-larger-than] Change this to have the actual attribute array allocated statically and then just add the instance number on the per-instance copy. Fixes: 699ea52 ("EDAC: Add a memory repair control feature") Signed-off-by: Arnd Bergmann <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/[email protected]
1 parent 10fa9a4 commit 815703e

File tree

1 file changed

+22
-34
lines changed

1 file changed

+22
-34
lines changed

drivers/edac/mem_repair.c

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -286,17 +286,26 @@ static umode_t mem_repair_attr_visible(struct kobject *kobj, struct attribute *a
286286
return 0;
287287
}
288288

289-
#define MR_ATTR_RO(_name, _instance) \
290-
((struct edac_mem_repair_dev_attr) { .dev_attr = __ATTR_RO(_name), \
291-
.instance = _instance })
292-
293-
#define MR_ATTR_WO(_name, _instance) \
294-
((struct edac_mem_repair_dev_attr) { .dev_attr = __ATTR_WO(_name), \
295-
.instance = _instance })
296-
297-
#define MR_ATTR_RW(_name, _instance) \
298-
((struct edac_mem_repair_dev_attr) { .dev_attr = __ATTR_RW(_name), \
299-
.instance = _instance })
289+
static const struct device_attribute mem_repair_dev_attr[] = {
290+
[MR_TYPE] = __ATTR_RO(repair_type),
291+
[MR_PERSIST_MODE] = __ATTR_RW(persist_mode),
292+
[MR_SAFE_IN_USE] = __ATTR_RO(repair_safe_when_in_use),
293+
[MR_HPA] = __ATTR_RW(hpa),
294+
[MR_MIN_HPA] = __ATTR_RO(min_hpa),
295+
[MR_MAX_HPA] = __ATTR_RO(max_hpa),
296+
[MR_DPA] = __ATTR_RW(dpa),
297+
[MR_MIN_DPA] = __ATTR_RO(min_dpa),
298+
[MR_MAX_DPA] = __ATTR_RO(max_dpa),
299+
[MR_NIBBLE_MASK] = __ATTR_RW(nibble_mask),
300+
[MR_BANK_GROUP] = __ATTR_RW(bank_group),
301+
[MR_BANK] = __ATTR_RW(bank),
302+
[MR_RANK] = __ATTR_RW(rank),
303+
[MR_ROW] = __ATTR_RW(row),
304+
[MR_COLUMN] = __ATTR_RW(column),
305+
[MR_CHANNEL] = __ATTR_RW(channel),
306+
[MR_SUB_CHANNEL] = __ATTR_RW(sub_channel),
307+
[MEM_DO_REPAIR] = __ATTR_WO(repair)
308+
};
300309

301310
static int mem_repair_create_desc(struct device *dev,
302311
const struct attribute_group **attr_groups,
@@ -305,34 +314,13 @@ static int mem_repair_create_desc(struct device *dev,
305314
struct edac_mem_repair_context *ctx;
306315
struct attribute_group *group;
307316
int i;
308-
struct edac_mem_repair_dev_attr dev_attr[] = {
309-
[MR_TYPE] = MR_ATTR_RO(repair_type, instance),
310-
[MR_PERSIST_MODE] = MR_ATTR_RW(persist_mode, instance),
311-
[MR_SAFE_IN_USE] = MR_ATTR_RO(repair_safe_when_in_use, instance),
312-
[MR_HPA] = MR_ATTR_RW(hpa, instance),
313-
[MR_MIN_HPA] = MR_ATTR_RO(min_hpa, instance),
314-
[MR_MAX_HPA] = MR_ATTR_RO(max_hpa, instance),
315-
[MR_DPA] = MR_ATTR_RW(dpa, instance),
316-
[MR_MIN_DPA] = MR_ATTR_RO(min_dpa, instance),
317-
[MR_MAX_DPA] = MR_ATTR_RO(max_dpa, instance),
318-
[MR_NIBBLE_MASK] = MR_ATTR_RW(nibble_mask, instance),
319-
[MR_BANK_GROUP] = MR_ATTR_RW(bank_group, instance),
320-
[MR_BANK] = MR_ATTR_RW(bank, instance),
321-
[MR_RANK] = MR_ATTR_RW(rank, instance),
322-
[MR_ROW] = MR_ATTR_RW(row, instance),
323-
[MR_COLUMN] = MR_ATTR_RW(column, instance),
324-
[MR_CHANNEL] = MR_ATTR_RW(channel, instance),
325-
[MR_SUB_CHANNEL] = MR_ATTR_RW(sub_channel, instance),
326-
[MEM_DO_REPAIR] = MR_ATTR_WO(repair, instance)
327-
};
328-
329317
ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
330318
if (!ctx)
331319
return -ENOMEM;
332320

333321
for (i = 0; i < MR_MAX_ATTRS; i++) {
334-
memcpy(&ctx->mem_repair_dev_attr[i],
335-
&dev_attr[i], sizeof(dev_attr[i]));
322+
ctx->mem_repair_dev_attr[i].dev_attr = mem_repair_dev_attr[i];
323+
ctx->mem_repair_dev_attr[i].instance = instance;
336324
ctx->mem_repair_attrs[i] =
337325
&ctx->mem_repair_dev_attr[i].dev_attr.attr;
338326
}

0 commit comments

Comments
 (0)