RE: [PATCH 2/2] EDAC/device: 3 to 1 allocations in edac_dev_feat_ctx

From: Zhuo, Qiuxu

Date: Fri May 01 2026 - 10:59:16 EST


> From: Rosen Penev <rosenp@xxxxxxxxx>
> Sent: Friday, May 1, 2026 6:01 AM
> To: linux-edac@xxxxxxxxxxxxxxx
> Cc: Borislav Petkov <bp@xxxxxxxxx>; Luck, Tony <tony.luck@xxxxxxxxx>; Kees
> Cook <kees@xxxxxxxxxx>; Gustavo A. R. Silva <gustavoars@xxxxxxxxxx>; open
> list <linux-kernel@xxxxxxxxxxxxxxx>; open list:KERNEL HARDENING (not
> covered by other areas):Keyword:\b__counted_by(_le|_be)?\b <linux-
> hardening@xxxxxxxxxxxxxxx>
> Subject: [PATCH 2/2] EDAC/device: 3 to 1 allocations in edac_dev_feat_ctx
>
> Simplifies memory handling slightly by using a flexible array member.
>
> Signed-off-by: Rosen Penev <rosenp@xxxxxxxxx>
> ---
> drivers/edac/edac_device.c | 40 +++++++++++++-------------------------
> include/linux/edac.h | 2 +-
> 2 files changed, 15 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c index
> 9c21997a50e0..a6c41ce68f13 100644
> --- a/drivers/edac/edac_device.c
> +++ b/drivers/edac/edac_device.c
> @@ -569,8 +569,6 @@ static void edac_dev_release(struct device *dev) {
> struct edac_dev_feat_ctx *ctx = container_of(dev, struct
> edac_dev_feat_ctx, dev);
>
> - kfree(ctx->mem_repair);
> - kfree(ctx->scrub);
> kfree(ctx->dev.groups);
> kfree(ctx);
> }
> @@ -612,6 +610,7 @@ int edac_dev_register(struct device *parent, char
> *name,
> int attr_gcnt = 0;
> int ret = -ENOMEM;
> int scrub_cnt = 0;
> + size_t alloc_size;
> int feat;
>
> if (!parent || !name || !num_features || !ras_features) @@ -636,26
> +635,18 @@ int edac_dev_register(struct device *parent, char *name,
> }
> }
>
> - ctx = kzalloc_obj(*ctx);
> + alloc_size = struct_size(ctx, scrub, scrub_cnt);
> + alloc_size += sizeof(*ctx->mem_repair) * mem_repair_cnt;
> + ctx = kzalloc(alloc_size, GFP_KERNEL);
> if (!ctx)
> return -ENOMEM;
>
> + ctx->mem_repair = ctx->scrub + scrub_cnt;

The same concerns about pointer alignment risk and code readability as in:
https://lore.kernel.org/all/CY8PR11MB7134BF3800324EFA1B3172AA89322@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/

-Qiuxu