EDAC/device: Use flexible array for instances
PATCH 1/1 EDAC/device: Use flexible array for instances
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 <[email protected]>
--- drivers/edac/edac_device.c | 13 ++++--------- drivers/edac/edac_device.h | 12 ++++++------ 2 files changed, 10 insertions(+), 15 deletions(-)
drivers/edac/edac_device.c +4 -9
@@ -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];
drivers/edac/edac_device.h +6 -6
@@ -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); } }
Signature · 1 line
2.54.0