EDAC/ecs: simplify allocation for context
PATCH v2 1/1 EDAC/ecs: simplify allocation for context
Use a flexible array member to combine allocations
Add __counted_by for extra runtime analysis.
Signed-off-by Rosen Penev <[email protected]>
---
v2: use devm_kzalloc_flex
drivers/edac/ecs.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/edac/ecs.c +2 -7
@@ -33,7 +33,7 @@ struct edac_ecs_fru_context {struct edac_ecs_context {u16 num_media_frus; -struct edac_ecs_fru_context *fru_ctxs; + struct edac_ecs_fru_context fru_ctxs[] __counted_by(num_media_frus); };#define TO_ECS_DEV_ATTR (_dev_attr) \
@@ -149,16 +149,11 @@ static int ecs_create_desc(struct device *ecs_dev, const struct attribute_groupstruct edac_ecs_context *ecs_ctx;u32 fru; - ecs_ctx =devm_kzalloc_obj (ecs_dev, *ecs_ctx); + ecs_ctx =devm_kzalloc_flex (ecs_dev, *ecs_ctx, fru_ctxs, num_media_frus);if (!ecs_ctx)return -ENOMEM ; ecs_ctx->num_media_frus = num_media_frus; - ecs_ctx->fru_ctxs =devm_kzalloc_objs (ecs_dev, *ecs_ctx->fru_ctxs, - num_media_frus); -if (!ecs_ctx->fru_ctxs) -return -ENOMEM ; -for (fru =0 ; fru < num_media_frus; fru++) {struct edac_ecs_fru_context *fru_ctx = &ecs_ctx->fru_ctxs[fru];struct attribute_group *group = &fru_ctx->group;
Signature · 1 line
2.56.0
Quoted 8 lines
From: Rosen Penev <[email protected]>
Sent: Wednesday, November 11, 2026 10:18 AM
To: Borislav Petkov <[email protected]>; Tony Luck <[email protected]>; Kees Cook <[email protected]>
Cc: Gustavo A. R. Silva <[email protected]>; [email protected]; linux- [email protected]; [email protected]
Subject: [PATCH v2] EDAC/ecs: simplify allocation for context
Quoted 8 lines
External email: Use caution opening links or attachments
Use a flexible array member to combine allocations
Add
__counted_byfor extra runtime analysis.Signed-off-by Rosen Penev <[email protected]>
LGTM. Thanks.
Reviewed-by Qiuxu Zhuo <[email protected]>