All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rosen Penev <rosenp@gmail.com>
To: linux-edac@vger.kernel.org
Cc: Yazen Ghannam <Yazen.Ghannam@amd.com>,
	Tony Luck <tony.luck@intel.com>, Borislav Petkov <bp@alien8.de>,
	linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] RAS/AMD/FMPM: use struct_size_t
Date: Mon, 16 Mar 2026 20:16:50 -0700	[thread overview]
Message-ID: <20260317031650.93712-1-rosenp@gmail.com> (raw)

Avoids manual size calculation with the proper helper.

Also use kzalloc_flex for the same reason.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/ras/amd/fmpm.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/ras/amd/fmpm.c b/drivers/ras/amd/fmpm.c
index 34ef75af31cb..af862fbb04a8 100644
--- a/drivers/ras/amd/fmpm.c
+++ b/drivers/ras/amd/fmpm.c
@@ -150,7 +150,7 @@ static unsigned int max_nr_fru;
 /* Total length of record including headers and list of descriptor entries. */
 static size_t max_rec_len;
 
-#define FMPM_MAX_REC_LEN (sizeof(struct fru_rec) + (sizeof(struct cper_fru_poison_desc) * 255))
+#define FMPM_MAX_REC_LEN struct_size_t(struct fru_rec, entries, 255)
 
 /* Total number of SPA entries across all FRUs. */
 static unsigned int spa_nr_entries;
@@ -794,8 +794,7 @@ static int get_system_info(void)
 
 	spa_nr_entries = max_nr_fru * max_nr_entries;
 
-	max_rec_len  = sizeof(struct fru_rec);
-	max_rec_len += sizeof(struct cper_fru_poison_desc) * max_nr_entries;
+	max_rec_len = struct_size_t(struct fru_rec, entries, max_nr_entries);
 
 	pr_info("max FRUs: %u, max entries: %u, max record length: %lu\n",
 		 max_nr_fru, max_nr_entries, max_rec_len);
@@ -826,7 +825,7 @@ static int allocate_records(void)
 	}
 
 	for (i = 0; i < max_nr_fru; i++) {
-		fru_records[i] = kzalloc(max_rec_len, GFP_KERNEL);
+		fru_records[i] = kzalloc_flex(*fru_records[i], entries, max_nr_entries);
 		if (!fru_records[i]) {
 			ret = -ENOMEM;
 			goto out_free;
-- 
2.53.0


             reply	other threads:[~2026-03-17  3:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-17  3:16 Rosen Penev [this message]
2026-03-19 16:28 ` [PATCH] RAS/AMD/FMPM: use struct_size_t Yazen Ghannam
2026-09-19  3:54   ` Borislav Petkov
2026-09-21 15:36     ` Yazen Ghannam
2026-09-21 17:52       ` Borislav Petkov

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=20260317031650.93712-1-rosenp@gmail.com \
    --to=rosenp@gmail.com \
    --cc=Yazen.Ghannam@amd.com \
    --cc=bp@alien8.de \
    --cc=linux-edac@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.