Skip to contentSkip to conversation

EDAC: fix a limit calculation in calculate_dimm_size()

PATCH In review Dan Carpenter 2 participants 4 messages Dec 5, 2025 – Dec 10, 2025

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

PATCH 1/1 EDAC: fix a limit calculation in calculate_dimm_size()

The snprintf() can't really overflow because we're writing a max of 42 bytes to a PAGE_SIZE buffer. But my static checker complains because the limit calculation doesn't take the first 11 bytes into consideration. Fix this for the sake of correctness even though it doesn't affect runtime.

Fixes 68d086f89b80 ("i5400_edac: improve debug messages to better represent the filled memory")
---
 drivers/edac/i5400_edac.c | 1 +
 1 file changed, 1 insertion(+)
drivers/edac/i5400_edac.c +1 -0
index b5cf25905b05..81c93ba957a0 100644
@@ -1033,6 +1033,7 @@ static void calculate_dimm_size(struct i5400_pvt *pvt)
 
 	n = snprintf(p, space, "           ");
 	p += n;
+	space -= n;
 	for (branch = 0; branch < MAX_BRANCHES; branch++) {
 		n = snprintf(p, space, "       branch %d       | ", branch);
 		p += n;
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#1 lore raw

Hi Dan,

Quoted 7 lines

From: Dan Carpenter <[email protected]>
Sent: Friday, December 5, 2025 7:10 PM
To: Mauro Carvalho Chehab <[email protected]>
Cc: Borislav Petkov <[email protected]>; Luck, Tony <[email protected]>; Aristeu Rozanski <[email protected]>; [email protected]; linux- [email protected]; [email protected]
Subject: [PATCH] EDAC: fix a limit calculation in calculate_dimm_size()

Please use the subject style as in most other EDAC files:

EDAC/i5400: Fix a limit calculation in calculate_dimm_size()

Quoted 25 lines

The snprintf() can't really overflow because we're writing a max of 42 bytes to a PAGE_SIZE buffer. But my static checker complains because the limit calculation doesn't take the first 11 bytes into consideration. Fix this for the sake of correctness even though it doesn't affect runtime.

Fixes 68d086f89b80 ("i5400_edac: improve debug messages to better

represent the filled memory")

---
 drivers/edac/i5400_edac.c | 1 +
 1 file changed, 1 insertion(+)
drivers/edac/i5400_edac.c index renamed from drivers/edac/i5400_edac.c +0 -0

b5cf25905b05..81c93ba957a0 100644

drivers/edac/i5400_edac.c +1 -0
@@ -1033,6 +1033,7 @@ static void calculate_dimm_size(struct i5400_pvt
 *pvt)
 
 	n = snprintf(p, space, "           ");
 	p += n;
+	space -= n;
 	for (branch = 0; branch < MAX_BRANCHES; branch++) {
 		n = snprintf(p, space, "       branch %d       | ", branch);
Quoted 4 lines

p += n;
--
2.51.0

At line 1029 in the original i5400_edac.c file, there is an incorrect extra "space -= n;" code line. Please also remove it.

https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/edac/i5400_edac.c#n1029

If with the above extra fix, your subject may need to update as follows:

EDAC/i5400: Fix limit calculations in calculate_dimm_size()

Other than that,

#2 lore raw

Thanks for the review. All good points. I have resent the patch.

regards,
dan carpenter

#3 lore raw
Quoted 11 lines

From: Dan Carpenter <[email protected]>
Sent: Tuesday, December 9, 2025 10:38 PM
To: Zhuo, Qiuxu <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>; Borislav Petkov <[email protected]>; Luck, Tony <[email protected]>; Aristeu Rozanski <[email protected]>; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH] EDAC: fix a limit calculation in calculate_dimm_size()

Thanks for the review. All good points. I have resent the patch.

Thanks for your update.

-Qiuxu