All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thorsten Blum <blum@kernel.org>
To: "David S. Miller" <davem@davemloft.net>,
	Andreas Larsson <andreas@gaisler.com>
Cc: Thorsten Blum <blum@kernel.org>,
	sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] sparc: chmc: Use buffer lengths when formatting DIMM labels
Date: Sun,  1 Nov 2026 14:24:07 +0100	[thread overview]
Message-ID: <20261101132407.132460-4-blum@kernel.org> (raw)
In-Reply-To: <20261101132407.132460-3-blum@kernel.org>

Replace unbounded sprintf() calls with the safer snprintf() and
scnprintf() to take the buffer lengths into account. When appending
multiple labels, use scnprintf()'s return value instead of manually
calling strlen().

Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 arch/sparc/kernel/chmc.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/arch/sparc/kernel/chmc.c b/arch/sparc/kernel/chmc.c
index ef31625272fa..9d7d8f791133 100644
--- a/arch/sparc/kernel/chmc.c
+++ b/arch/sparc/kernel/chmc.c
@@ -318,17 +318,18 @@ static int jbusmc_print_dimm(int syndrome_code,
 
 		get_pin_and_dimm_str(syndrome_code, phys_addr, &pin,
 				     &dimm_str, prop, first_dimm);
-		sprintf(buf, "%s, pin %3d", dimm_str, pin);
+		snprintf(buf, buflen, "%s, pin %3d", dimm_str, pin);
 	} else {
-		int dimm;
+		int dimm, len;
 
 		/* Multi-bit error, we just dump out all the
 		 * dimm labels associated with this dimm group.
 		 */
 		for (dimm = 0; dimm < JB_NUM_DIMMS_PER_GROUP; dimm++) {
-			sprintf(buf, "%s ",
-				prop->dimm_labels[first_dimm + dimm]);
-			buf += strlen(buf);
+			len = scnprintf(buf, buflen, "%s ",
+					prop->dimm_labels[first_dimm + dimm]);
+			buf += len;
+			buflen -= len;
 		}
 	}
 
@@ -561,17 +562,18 @@ static int chmc_print_dimm(int syndrome_code,
 
 		get_pin_and_dimm_str(syndrome_code, phys_addr, &pin,
 				     &dimm_str, prop, first_dimm);
-		sprintf(buf, "%s, pin %3d", dimm_str, pin);
+		snprintf(buf, buflen, "%s, pin %3d", dimm_str, pin);
 	} else {
-		int dimm;
+		int dimm, len;
 
 		/* Multi-bit error, we just dump out all the
 		 * dimm labels associated with this bank.
 		 */
 		for (dimm = 0; dimm < CHMCTRL_NDIMMS; dimm++) {
-			sprintf(buf, "%s ",
-				prop->dimm_labels[first_dimm + dimm]);
-			buf += strlen(buf);
+			len = scnprintf(buf, buflen, "%s ",
+					prop->dimm_labels[first_dimm + dimm]);
+			buf += len;
+			buflen -= len;
 		}
 	}
 	return 0;

      reply	other threads:[~2026-11-01 13:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-01 13:24 [PATCH 1/2] sparc: chmc: Use strscpy() for unknown DIMM labels Thorsten Blum
2026-11-01 13:24 ` Thorsten Blum [this message]

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=20261101132407.132460-4-blum@kernel.org \
    --to=blum@kernel.org \
    --cc=andreas@gaisler.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sparclinux@vger.kernel.org \
    /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.