> From: Rosen Penev <[email protected]> > Sent: Friday, May 1, 2026 6:01 AM > To: [email protected] > Cc: Borislav Petkov <[email protected]>; Luck, Tony <[email protected]>; Kees > Cook <[email protected]>; Gustavo A. R. Silva <[email protected]>; open > list <[email protected]>; open list:KERNEL HARDENING (not > covered by other areas):Keyword:\b__counted_by(_le|_be)?\b <linux- > [email protected]> > 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 <[email protected]> > --- > 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/cy8pr11mb7134bf3800324efa1b3172aa89...@cy8pr11mb7134.namprd11.prod.outlook.com/ -Qiuxu

