Linux Hardening
 help / color / mirror / Atom feed
* [PATCH] EDAC/device: Use flexible array for instances
@ 2026-05-12  3:08 Rosen Penev
  0 siblings, 0 replies; only message in thread
From: Rosen Penev @ 2026-05-12  3:08 UTC (permalink / raw)
  To: linux-edac
  Cc: Borislav Petkov, Tony Luck, Kees Cook, Gustavo A. R. Silva,
	open list,
	open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b

Store EDAC device instances in the control info allocation instead
of allocating them separately.

This ties the instances lifetime directly to the control info object,
removes a separate allocation failure path, and lets __counted_by()
describe the array bounds.

Assisted-by: Codex:GPT-5.5
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/edac/edac_device.c | 13 ++++---------
 drivers/edac/edac_device.h | 12 ++++++------
 2 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
index cf0d3c2dfc04..30a1fb392fc4 100644
--- a/drivers/edac/edac_device.c
+++ b/drivers/edac/edac_device.c
@@ -59,23 +59,19 @@ edac_device_alloc_ctl_info(unsigned pvt_sz, char *dev_name, unsigned nr_instance
 			   int device_index)
 {
 	struct edac_device_block *dev_blk, *blk_p, *blk;
-	struct edac_device_instance *dev_inst, *inst;
 	struct edac_device_ctl_info *dev_ctl;
+	struct edac_device_instance *inst;
 	unsigned instance, block;
 	void *pvt;
 	int err;
 
 	edac_dbg(4, "instances=%d blocks=%d\n", nr_instances, nr_blocks);
 
-	dev_ctl = kzalloc_obj(struct edac_device_ctl_info);
+	dev_ctl = kzalloc_flex(*dev_ctl, instances, nr_instances);
 	if (!dev_ctl)
 		return NULL;
 
-	dev_inst = kzalloc_objs(struct edac_device_instance, nr_instances);
-	if (!dev_inst)
-		goto free;
-
-	dev_ctl->instances = dev_inst;
+	dev_ctl->nr_instances = nr_instances;
 
 	dev_blk = kzalloc_objs(struct edac_device_block,
 			       nr_instances * nr_blocks);
@@ -93,7 +89,6 @@ edac_device_alloc_ctl_info(unsigned pvt_sz, char *dev_name, unsigned nr_instance
 	}
 
 	dev_ctl->dev_idx	= device_index;
-	dev_ctl->nr_instances	= nr_instances;
 
 	/* Default logging of CEs and UEs */
 	dev_ctl->log_ce = 1;
@@ -104,7 +99,7 @@ edac_device_alloc_ctl_info(unsigned pvt_sz, char *dev_name, unsigned nr_instance
 
 	/* Initialize every Instance */
 	for (instance = 0; instance < nr_instances; instance++) {
-		inst = &dev_inst[instance];
+		inst = &dev_ctl->instances[instance];
 		inst->ctl = dev_ctl;
 		inst->nr_blocks = nr_blocks;
 		blk_p = &dev_blk[instance * nr_blocks];
diff --git a/drivers/edac/edac_device.h b/drivers/edac/edac_device.h
index 24c1921aa490..72414ec8ad6b 100644
--- a/drivers/edac/edac_device.h
+++ b/drivers/edac/edac_device.h
@@ -199,11 +199,7 @@ struct edac_device_ctl_info {
 	 */
 	char name[EDAC_DEVICE_NAME_LEN + 1];
 
-	/* Number of instances supported on this control structure
-	 * and the array of those instances
-	 */
-	u32 nr_instances;
-	struct edac_device_instance *instances;
+	/* Array of all blocks for all instances. */
 	struct edac_device_block *blocks;
 
 	/* Event counters for the this whole EDAC Device */
@@ -213,6 +209,11 @@ struct edac_device_ctl_info {
 	 * device this structure controls
 	 */
 	struct kobject kobj;
+
+	/* Number of instances supported on this control structure. */
+	u32 nr_instances;
+	/* Array of instances for this control structure. */
+	struct edac_device_instance instances[] __counted_by(nr_instances);
 };
 
 /* To get from the instance's wq to the beginning of the ctl structure */
@@ -342,7 +343,6 @@ static inline void __edac_device_free_ctl_info(struct edac_device_ctl_info *ci)
 	if (ci) {
 		kfree(ci->pvt_info);
 		kfree(ci->blocks);
-		kfree(ci->instances);
 		kfree(ci);
 	}
 }
-- 
2.54.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-05-12  3:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-12  3:08 [PATCH] EDAC/device: Use flexible array for instances Rosen Penev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox