Skip to contentSkip to conversation

RAS/AMD/FMPM: use struct_size_t

PATCH In review Rosen Penev 3 participants 5 messages Mar 17 – Sep 21

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RAS/AMD/FMPM: use struct_size_t

Avoids manual size calculation with the proper helper.

Also use kzalloc_flex for the same reason.

---
 drivers/ras/amd/fmpm.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/ras/amd/fmpm.c +3 -4
index 34ef75af31cb..af862fbb04a8 100644
@@ -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;
Signature · 1 line
2.53.0
maintainer
#2 lore raw
Quoted 8 lines · Yazen Ghannam
Quoted 5 lines · Rosen Penev

Avoids manual size calculation with the proper helper.

Also use kzalloc_flex for the same reason.

https://sashiko.dev/#/patchset/20260317031650.93712-1-rosenp%40gmail.com

Yazen, there are funnies for you too in there.

:-)

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer
#3 lore raw
Quoted 8 lines · Borislav Petkov
Quoted 7 lines · Yazen Ghannam
Quoted 5 lines · Rosen Penev

Avoids manual size calculation with the proper helper.

Also use kzalloc_flex for the same reason.

Quoted 8 lines
Quoted 1 line

https://sashiko.dev/#/patchset/20260317031650.93712-1-rosenp%40gmail.com

Yazen, there are funnies for you too in there.

:-)

As always :P.

BTW, how are you triggering Sashiko?

I see that Sashiko replies directly on the linux-pci list.
Ex. https://lore.kernel.org/all/[email protected]/

It's nice to have the email replies rather than just the web interface.

Thanks,
Yazen

maintainer
#4 lore raw
Quoted 1 line · Yazen Ghannam

BTW, how are you triggering Sashiko?

I don't. It reviews everything that lands on LKML.

Quoted 4 lines

I see that Sashiko replies directly on the linux-pci list.
Ex. https://lore.kernel.org/all/[email protected]/

It's nice to have the email replies rather than just the web interface.

I think that can be configured on a per subsystem basis but I'm not sure.

There were some threads flying by on the subject.

You can always simply search the web interface for reviews. It is pretty quick with the review, usually.

HTH.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette