Skip to contentSkip to conversation

EDAC/ecs: simplify allocation for context

PATCH New Rosen Penev 1 participant 1 message Apr 30 EDAC-core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 EDAC/ecs: simplify allocation for context

Use a flexible array member to combine allocations

Add __counted_by for extra runtime analysis.

---
 drivers/edac/ecs.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/edac/ecs.c +2 -8
index 51c451c7f0f0..f0833080c5cc 100644
@@ -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,17 +149,11 @@ static int ecs_create_desc(struct device *ecs_dev, const struct attribute_group
 	struct edac_ecs_context *ecs_ctx;
 	u32 fru;
 
-	ecs_ctx = devm_kzalloc(ecs_dev, sizeof(*ecs_ctx), GFP_KERNEL);
+	ecs_ctx = devm_kzalloc(ecs_dev, struct_size(ecs_ctx, fru_ctxs, num_media_frus), GFP_KERNEL);
 	if (!ecs_ctx)
 		return -ENOMEM;
 
 	ecs_ctx->num_media_frus = num_media_frus;
-	ecs_ctx->fru_ctxs = devm_kcalloc(ecs_dev, num_media_frus,
-					 sizeof(*ecs_ctx->fru_ctxs),
-					 GFP_KERNEL);
-	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.54.0