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

Zhuo, Qiuxu
2026-05-01T14:55:00Z

> From: Rosen Penev <rosenp@gmail.com>
> Sent: Friday, May 1, 2026 6:01 AM
> To: linux-edac@vger.kernel.org
> Cc: Borislav Petkov <bp@alien8.de>; Luck, Tony <tony.luck@intel.com>; Kees
> Cook <kees@kernel.org>; Gustavo A. R. Silva <gustavoars@kernel.org>; open
> list <linux-kernel@vger.kernel.org>; open list:KERNEL HARDENING (not
> covered by other areas):Keyword:\b__counted_by(_le|_be)?\b <linux-
> hardening@vger.kernel.org>
> 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@gmail.com>
> ---
> 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@CY8PR11MB7134.namprd11.prod.outlook.com/

-Qiuxu