From: Rosen Penev <rosenp@gmail.com>
To: linux-edac@vger.kernel.org
Cc: Borislav Petkov <bp@alien8.de>, Tony Luck <tony.luck@intel.com>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-kernel@vger.kernel.org (open list),
linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not
covered by other areas):Keyword:\b__counted_by(_le|_be)?\b)
Subject: [PATCH] EDAC/device: Use flexible array for instances
Date: Mon, 11 May 2026 20:08:21 -0700 [thread overview]
Message-ID: <20260512030821.47802-1-rosenp@gmail.com> (raw)
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
reply other threads:[~2026-05-12 3:08 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260512030821.47802-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=bp@alien8.de \
--cc=gustavoars@kernel.org \
--cc=kees@kernel.org \
--cc=linux-edac@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tony.luck@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox