public inbox for linux-edac@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] EDAC: fix a limit calculation in calculate_dimm_size()
@ 2025-12-05 11:10 Dan Carpenter
  2025-12-05 15:36 ` Zhuo, Qiuxu
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2025-12-05 11:10 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Borislav Petkov, Tony Luck, Aristeu Rozanski, linux-edac,
	linux-kernel, kernel-janitors

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")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/edac/i5400_edac.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
index b5cf25905b05..81c93ba957a0 100644
--- a/drivers/edac/i5400_edac.c
+++ b/drivers/edac/i5400_edac.c
@@ -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;
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [PATCH] EDAC: fix a limit calculation in calculate_dimm_size()
  2025-12-05 11:10 [PATCH] EDAC: fix a limit calculation in calculate_dimm_size() Dan Carpenter
@ 2025-12-05 15:36 ` Zhuo, Qiuxu
  2025-12-09 14:37   ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Zhuo, Qiuxu @ 2025-12-05 15:36 UTC (permalink / raw)
  To: Dan Carpenter, Mauro Carvalho Chehab
  Cc: Borislav Petkov, Luck, Tony, Aristeu Rozanski,
	linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org

Hi Dan,

> From: Dan Carpenter <dan.carpenter@linaro.org>
> Sent: Friday, December 5, 2025 7:10 PM
> To: Mauro Carvalho Chehab <mchehab@kernel.org>
> Cc: Borislav Petkov <bp@alien8.de>; Luck, Tony <tony.luck@intel.com>;
> Aristeu Rozanski <arozansk@redhat.com>; linux-edac@vger.kernel.org; linux-
> kernel@vger.kernel.org; kernel-janitors@vger.kernel.org
> 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()

> 
> 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")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
>  drivers/edac/i5400_edac.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c index
> b5cf25905b05..81c93ba957a0 100644
> --- a/drivers/edac/i5400_edac.c
> +++ b/drivers/edac/i5400_edac.c
> @@ -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;
> --
> 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,

   Reviewed-by: Qiuxu Zhuo <qiuxu.zhuo@intel.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] EDAC: fix a limit calculation in calculate_dimm_size()
  2025-12-05 15:36 ` Zhuo, Qiuxu
@ 2025-12-09 14:37   ` Dan Carpenter
  2025-12-10  1:27     ` Zhuo, Qiuxu
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2025-12-09 14:37 UTC (permalink / raw)
  To: Zhuo, Qiuxu
  Cc: Mauro Carvalho Chehab, Borislav Petkov, Luck, Tony,
	Aristeu Rozanski, linux-edac@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org

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

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] EDAC: fix a limit calculation in calculate_dimm_size()
  2025-12-09 14:37   ` Dan Carpenter
@ 2025-12-10  1:27     ` Zhuo, Qiuxu
  0 siblings, 0 replies; 4+ messages in thread
From: Zhuo, Qiuxu @ 2025-12-10  1:27 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Mauro Carvalho Chehab, Borislav Petkov, Luck, Tony,
	Aristeu Rozanski, linux-edac@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org

> From: Dan Carpenter <dan.carpenter@linaro.org>
> Sent: Tuesday, December 9, 2025 10:38 PM
> To: Zhuo, Qiuxu <qiuxu.zhuo@intel.com>
> Cc: Mauro Carvalho Chehab <mchehab@kernel.org>; Borislav Petkov
> <bp@alien8.de>; Luck, Tony <tony.luck@intel.com>; Aristeu Rozanski
> <arozansk@redhat.com>; linux-edac@vger.kernel.org; linux-
> kernel@vger.kernel.org; kernel-janitors@vger.kernel.org
> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-12-10  1:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-05 11:10 [PATCH] EDAC: fix a limit calculation in calculate_dimm_size() Dan Carpenter
2025-12-05 15:36 ` Zhuo, Qiuxu
2025-12-09 14:37   ` Dan Carpenter
2025-12-10  1:27     ` Zhuo, Qiuxu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox