Skip to contentSkip to conversation

EDAC/device: Use flexible array for scrub data

PATCH New Rosen Penev 1 participant 1 message Jul 29 EDAC-core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 EDAC/device: Use flexible array for scrub data

Store EDAC scrub feature data in the device feature context allocation instead of allocating it separately.

This ties the scrub data lifetime directly to the feature context, removes a separate allocation failure path.

Assisted-by Codex:GPT-5.5
---
 drivers/edac/edac_device.c | 12 ++----------
 include/linux/edac.h       |  2 +-
 2 files changed, 3 insertions(+), 11 deletions(-)
drivers/edac/edac_device.c +2 -10
index cf0d3c2dfc04..fd3e4631ce17 100644
@@ -577,7 +577,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);
 }
@@ -643,7 +642,7 @@ int edac_dev_register(struct device *parent, char *name,
 		}
 	}
 
-	ctx = kzalloc_obj(*ctx);
+	ctx = kzalloc_flex(*ctx, scrub, scrub_cnt);
 	if (!ctx)
 		return -ENOMEM;
 
@@ -651,16 +650,10 @@ int edac_dev_register(struct device *parent, char *name,
 	if (!ras_attr_groups)
 		goto ctx_free;
 
-	if (scrub_cnt) {
-		ctx->scrub = kzalloc_objs(*ctx->scrub, scrub_cnt);
-		if (!ctx->scrub)
-			goto groups_free;
-	}
-
 	if (mem_repair_cnt) {
 		ctx->mem_repair = kzalloc_objs(*ctx->mem_repair, mem_repair_cnt);
 		if (!ctx->mem_repair)
-			goto data_mem_free;
+			goto groups_free;
 	}
 
 	attr_gcnt = 0;
@@ -748,7 +741,6 @@ int edac_dev_register(struct device *parent, char *name,
 
 data_mem_free:
 	kfree(ctx->mem_repair);
-	kfree(ctx->scrub);
 groups_free:
 	kfree(ras_attr_groups);
 ctx_free:
include/linux/edac.h +1 -1
index a6b47d27052a..3d8ee12c11be 100644
@@ -864,9 +864,9 @@ struct edac_dev_data {
 struct edac_dev_feat_ctx {
 	struct device dev;
 	void *private;
-	struct edac_dev_data *scrub;
 	struct edac_dev_data ecs;
 	struct edac_dev_data *mem_repair;
+	struct edac_dev_data scrub[];
 };
 
 struct edac_dev_feature {
Signature · 1 line
2.55.0