From: Rosen Penev <rosenp@gmail.com>
To: linux-edac@vger.kernel.org
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
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: [PATCHv2] EDAC/i7core: Use kzalloc_flex()
Date: Fri, 13 Mar 2026 14:59:00 -0700 [thread overview]
Message-ID: <20260313215900.6724-1-rosenp@gmail.com> (raw)
Simplifies allocations by using a flexible array member in this struct.
Add __counted_by to get extra runtime analysis. Move counting variable
assignment to right after allocation as required by __counted_by.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
Reviewed-by: Qiuxu Zhuo <qiuxu.zhuo@intel.com>
---
v2: change subject
drivers/edac/i7core_edac.c | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
index 0f783173d0ec..b87c4c6471ea 100644
--- a/drivers/edac/i7core_edac.c
+++ b/drivers/edac/i7core_edac.c
@@ -240,9 +240,9 @@ struct pci_id_table {
struct i7core_dev {
struct list_head list;
u8 socket;
- struct pci_dev **pdev;
- int n_devs;
struct mem_ctl_info *mci;
+ int n_devs;
+ struct pci_dev *pdev[] __counted_by(n_devs);
};
struct i7core_pvt {
@@ -455,18 +455,12 @@ static struct i7core_dev *alloc_i7core_dev(u8 socket,
{
struct i7core_dev *i7core_dev;
- i7core_dev = kzalloc_obj(*i7core_dev);
+ i7core_dev = kzalloc_flex(*i7core_dev, pdev, table->n_devs);
if (!i7core_dev)
return NULL;
- i7core_dev->pdev = kzalloc_objs(*i7core_dev->pdev, table->n_devs);
- if (!i7core_dev->pdev) {
- kfree(i7core_dev);
- return NULL;
- }
-
- i7core_dev->socket = socket;
i7core_dev->n_devs = table->n_devs;
+ i7core_dev->socket = socket;
list_add_tail(&i7core_dev->list, &i7core_edac_list);
return i7core_dev;
@@ -475,7 +469,6 @@ static struct i7core_dev *alloc_i7core_dev(u8 socket,
static void free_i7core_dev(struct i7core_dev *i7core_dev)
{
list_del(&i7core_dev->list);
- kfree(i7core_dev->pdev);
kfree(i7core_dev);
}
--
2.53.0
next reply other threads:[~2026-03-13 21:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-13 21:59 Rosen Penev [this message]
2026-03-13 22:19 ` [PATCHv2] EDAC/i7core: Use kzalloc_flex() Luck, Tony
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=20260313215900.6724-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=mchehab@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