EDAC/ i5000, i5400: fix snprintf limit
Subsystems (3)
v2 cover EDAC/ i5000, i5400: fix snprintf limit
These fixes don't affect runtime since the buffer is large enough but the size limits used for snprintf() limits aren't caculated correct.
Changes since v1:
* Fix i5000 as well.
* Fix the subject
* Delete some related dead code
Dan Carpenter (2):
EDAC/i5000: Fix snprintf() size calculation in calculate_dimm_size() EDAC/i5400: Fix snprintf() limit calculation in calculate_dimm_size()
drivers/edac/i5000_edac.c | 1 + drivers/edac/i5400_edac.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
2.51.0
PATCH v2 1/2 EDAC/i5000: Fix snprintf() size 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 the limit calculation doesn't take the first 11 bytes that we wrote into consideration so the limit is not correct. Just fix it for correctness even though it doesn't affect runtime.
---
v2: new patch
drivers/edac/i5000_edac.c | 1 + 1 file changed, 1 insertion(+)
drivers/edac/i5000_edac.c +1 -0
@@ -1111,6 +1111,7 @@ static void calculate_dimm_size(struct i5000_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
PATCH v2 2/2 EDAC/i5400: Fix snprintf() limit calculation in calculate_dimm_size()
In reply to Dan CarpenterThe 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 space characters that we wrote into the buffer into consideration. Fix this for the sake of correctness even though it doesn't affect runtime.
Also delete an earlier "space -= n;" which was not used.
---
v2: Delete the earlier "space -= n" which is not used.
Fix the subject
drivers/edac/i5400_edac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/edac/i5400_edac.c +1 -1
@@ -1026,13 +1026,13 @@ static void calculate_dimm_size(struct i5400_pvt *pvt) space -= n; } - space -= n;edac_dbg (2 ,"%s\n" , mem_buffer); p = mem_buffer; space =PAGE_SIZE ; 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
RE: [PATCH v2 1/2] EDAC/i5000: Fix snprintf() size calculation in calculate_dimm_size()
In reply to Dan CarpenterQuoted 9 lines
From: Dan Carpenter <[email protected]>
Sent: Tuesday, December 9, 2025 10:37 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]
Subject: [PATCH v2 1/2] EDAC/i5000: Fixsnprintf()size calculation incalculate_dimm_size()
Quoted 8 lines
The
snprintf()can't really overflow because we're writing a max of 42 bytes to aPAGE_SIZEbuffer. But the limit calculation doesn't take the first 11 bytes that we wrote into consideration so the limit is not correct. Just fix it for correctness even though it doesn't affect runtime.Fixes 64e1fdaf55d6 ("i5000_edac: Fix the logic that retrieves memoryinformation")
Signed-off-by Dan Carpenter <[email protected]>
LGTM. Thanks.
Quoted 9 lines · Dan Carpenter
These fixes don't affect runtime since the buffer is large enough but the size limits used for
snprintf()limits aren't caculated correct.Changes since v1:
* Fix i5000 as well.
* Fix the subject
* Delete some related dead code
Quoted 7 lines
Dan Carpenter (2):
EDAC/i5000: Fixsnprintf()size calculation incalculate_dimm_size()EDAC/i5400: Fixsnprintf()limit calculation incalculate_dimm_size()drivers/edac/i5000_edac.c | 1 + drivers/edac/i5400_edac.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
Applied. Thanks.
-Tony