mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] sparc: chmc: Use strscpy() for unknown DIMM labels
@ 2026-11-01 13:24 Thorsten Blum
  2026-11-01 13:24 ` [PATCH 2/2] sparc: chmc: Use buffer lengths when formatting " Thorsten Blum
  0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2026-11-01 13:24 UTC (permalink / raw)
  To: David S. Miller, Andreas Larsson; +Cc: Thorsten Blum, sparclinux, linux-kernel

Replace the manual writes of "???" in jbusmc_print_dimm() and
chmc_print_dimm() with strscpy() to simplify the code and to take the
buffer lengths into account.

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

diff --git a/arch/sparc/kernel/chmc.c b/arch/sparc/kernel/chmc.c
index d935177b6953..ef31625272fa 100644
--- a/arch/sparc/kernel/chmc.c
+++ b/arch/sparc/kernel/chmc.c
@@ -304,10 +304,7 @@ static int jbusmc_print_dimm(int syndrome_code,
 	if (dp == NULL ||
 	    syndrome_code < SYNDROME_MIN ||
 	    syndrome_code > SYNDROME_MAX) {
-		buf[0] = '?';
-		buf[1] = '?';
-		buf[2] = '?';
-		buf[3] = '\0';
+		strscpy(buf, "???", buflen);
 		return 0;
 	}
 	p = dp->controller;
@@ -549,10 +546,7 @@ static int chmc_print_dimm(int syndrome_code,
 	if (bp == NULL ||
 	    syndrome_code < SYNDROME_MIN ||
 	    syndrome_code > SYNDROME_MAX) {
-		buf[0] = '?';
-		buf[1] = '?';
-		buf[2] = '?';
-		buf[3] = '\0';
+		strscpy(buf, "???", buflen);
 		return 0;
 	}
 

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

* [PATCH 2/2] sparc: chmc: Use buffer lengths when formatting DIMM labels
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Thorsten Blum @ 2026-11-01 13:24 UTC (permalink / raw)
  To: David S. Miller, Andreas Larsson; +Cc: Thorsten Blum, sparclinux, linux-kernel

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;

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

end of thread, other threads:[~2026-11-01 13:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-01 13:24 [PATCH 1/2] sparc: chmc: Use strscpy() for unknown DIMM labels Thorsten Blum
2026-11-01 13:24 ` [PATCH 2/2] sparc: chmc: Use buffer lengths when formatting " Thorsten Blum

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

all inboxes | Powered by JetHome®