Skip to contentSkip to conversation

sparc: PCI: Replace deprecated strcpy with strscpy

PATCH In review Thorsten Blum 3 participants 11 messages Sep 22, 2025 – Oct 18, 2025 SPARC + UltraSPARC (sparc/sparc64)

lore
Share & tools
lore
#0 lore raw

PATCH 1/8 sparc: PCI: Replace deprecated strcpy with strscpy

strcpy() is deprecated; use strscpy() instead.

No functional changes intended.

---
 arch/sparc/kernel/pcic.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/sparc/kernel/pcic.c +4 -3
index 25fe0a061732..f894ae79e78a 100644
@@ -16,6 +16,7 @@
 #include <linux/init.h>
 #include <linux/mm.h>
 #include <linux/slab.h>
+#include <linux/string.h>
 #include <linux/jiffies.h>
 
 #include <asm/swift.h> /* for cache flushing. */
@@ -352,7 +353,7 @@ int __init pcic_probe(void)
 	pbm = &pcic->pbm;
 	pbm->prom_node = node;
 	prom_getstring(node, "name", namebuf, 63);  namebuf[63] = 0;
-	strcpy(pbm->prom_name, namebuf);
+	strscpy(pbm->prom_name, namebuf);
 
 	{
 		extern int pcic_nmi_trap_patch[4];
@@ -477,7 +478,7 @@ static void pcic_map_pci_device(struct linux_pcic *pcic,
 	int j;
 
 	if (node == 0 || node == -1) {
-		strcpy(namebuf, "???");
+		strscpy(namebuf, "???");
 	} else {
 		prom_getstring(node, "name", namebuf, 63); namebuf[63] = 0;
 	}
@@ -536,7 +537,7 @@ pcic_fill_irq(struct linux_pcic *pcic, struct pci_dev *dev, int node)
 	char namebuf[64];
 
 	if (node == 0 || node == -1) {
-		strcpy(namebuf, "???");
+		strscpy(namebuf, "???");
 	} else {
 		prom_getstring(node, "name", namebuf, sizeof(namebuf));
 	}
Signature · 1 line
2.51.0
#1 lore raw

PATCH 2/8 sparc: parport: Replace deprecated strcpy with strscpy in ecpp_probe

strcpy() is deprecated; use strscpy() instead.

No functional changes intended.

---
 arch/sparc/include/asm/parport_64.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/sparc/include/asm/parport_64.h +2 -1
index 3068809ef9ad..78f14d6620bf 100644
@@ -9,6 +9,7 @@
 
 #include <linux/of.h>
 #include <linux/platform_device.h>
+#include <linux/string.h>
 
 #include <asm/ebus_dma.h>
 #include <asm/ns87303.h>
@@ -149,7 +150,7 @@ static int ecpp_probe(struct platform_device *op)
 	sparc_ebus_dmas[slot].info.callback = NULL;
 	sparc_ebus_dmas[slot].info.client_cookie = NULL;
 	sparc_ebus_dmas[slot].info.irq = 0xdeadbeef;
-	strcpy(sparc_ebus_dmas[slot].info.name, "parport");
+	strscpy(sparc_ebus_dmas[slot].info.name, "parport");
 	if (ebus_dma_register(&sparc_ebus_dmas[slot].info))
 		goto out_unmap_regs;
 
Signature · 1 line
2.51.0
#2 lore raw

PATCH 3/8 sparc: floppy: Replace deprecated strcpy with strscpy in sun_floppy_init

In reply to Thorsten Blum

strcpy() is deprecated; use strscpy() instead.

No functional changes intended.

---
 arch/sparc/include/asm/floppy_64.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/sparc/include/asm/floppy_64.h +2 -1
index b0f633ce3518..8d3ce6506607 100644
@@ -13,6 +13,7 @@
 #include <linux/of.h>
 #include <linux/of_platform.h>
 #include <linux/dma-mapping.h>
+#include <linux/string.h>
 
 #include <asm/auxio.h>
 
@@ -618,7 +619,7 @@ static unsigned long __init sun_floppy_init(void)
 		sun_pci_fd_ebus_dma.callback = sun_pci_fd_dma_callback;
 		sun_pci_fd_ebus_dma.client_cookie = NULL;
 		sun_pci_fd_ebus_dma.irq = FLOPPY_IRQ;
-		strcpy(sun_pci_fd_ebus_dma.name, "floppy");
+		strscpy(sun_pci_fd_ebus_dma.name, "floppy");
 		if (ebus_dma_register(&sun_pci_fd_ebus_dma))
 			return 0;
 
Signature · 1 line
2.51.0
#4 lore raw

PATCH 4/8 sparc: Replace deprecated strcpy with strscpy in prom_nextprop

In reply to Thorsten Blum

strcpy() is deprecated; use strscpy() instead.

No functional changes intended.

---
 arch/sparc/prom/tree_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sparc/prom/tree_64.c +1 -1
index 88793e5b0ab5..7388339bbd7e 100644
@@ -272,7 +272,7 @@ char *prom_nextprop(phandle node, const char *oprop, char *buffer)
 		return buffer;
 	}
 	if (oprop == buffer) {
-		strcpy (buf, oprop);
+		strscpy(buf, oprop);
 		oprop = buf;
 	}
 
Signature · 1 line
2.51.0
#5 lore raw

PATCH 5/8 sparc: Replace deprecated strcpy with strscpy

In reply to Thorsten Blum

strcpy() is deprecated; use strscpy() instead.

In ldom_set_var(), use pr_err() instead of printk(KERN_ERR) to silence a checkpatch warning.

No functional changes intended.

---
 arch/sparc/kernel/ds.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)
arch/sparc/kernel/ds.c +15 -12
index ffdc15588ac2..f7fc6f2af2f2 100644
@@ -781,14 +781,17 @@ void ldom_set_var(const char *var, const char *value)
 		} pkt;
 		char  *base, *p;
 		int msg_len, loops;
+		size_t var_len, value_len;
 
-		if (strlen(var) + strlen(value) + 2 >
-		    sizeof(pkt) - sizeof(pkt.header)) {
-			printk(KERN_ERR PFX
-				"contents length: %zu, which more than max: %lu,"
-				"so could not set (%s) variable to (%s).\n",
-				strlen(var) + strlen(value) + 2,
-				sizeof(pkt) - sizeof(pkt.header), var, value);
+		var_len = strlen(var) + 1;
+		value_len = strlen(value) + 1;
+
+		if (var_len + value_len > sizeof(pkt) - sizeof(pkt.header)) {
+			pr_err(PFX
+			       "contents length: %zu, which more than max: %lu,"
+			       "so could not set (%s) variable to (%s).\n",
+			       var_len + value_len,
+			       sizeof(pkt) - sizeof(pkt.header), var, value);
 			return;
 		}
 
@@ -797,10 +800,10 @@ void ldom_set_var(const char *var, const char *value)
 		pkt.header.data.handle = cp->handle;
 		pkt.header.msg.hdr.type = DS_VAR_SET_REQ;
 		base = p = &pkt.header.msg.name_and_value[0];
-		strcpy(p, var);
-		p += strlen(var) + 1;
-		strcpy(p, value);
-		p += strlen(value) + 1;
+		strscpy(p, var, var_len);
+		p += var_len;
+		strscpy(p, value, value_len);
+		p += value_len;
 
 		msg_len = (sizeof(struct ds_data) +
 			   sizeof(struct ds_var_set_msg) +
@@ -910,7 +913,7 @@ static int register_services(struct ds_info *dp)
 		pbuf.req.handle = cp->handle;
 		pbuf.req.major = 1;
 		pbuf.req.minor = 0;
-		strcpy(pbuf.id_buf, cp->service_id);
+		strscpy(pbuf.id_buf, cp->service_id);
 
 		err = __ds_send(lp, &pbuf, msg_len);
 		if (err > 0)
Signature · 1 line
2.51.0
#6 lore raw

PATCH 6/8 sparc32: Replace deprecated strcpy with strscpy

In reply to Thorsten Blum

strcpy() is deprecated; use strscpy() instead.

No functional changes intended.

---
 arch/sparc/kernel/prom_32.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
arch/sparc/kernel/prom_32.c +8 -5
index a67dd67f10c8..cd94f1e8d644 100644
@@ -187,14 +187,16 @@ char * __init build_path_component(struct device_node *dp)
 {
 	const char *name = of_get_property(dp, "name", NULL);
 	char tmp_buf[64], *n;
+	size_t n_sz;
 
 	tmp_buf[0] = '\0';
 	__build_path_component(dp, tmp_buf);
 	if (tmp_buf[0] == '\0')
-		strcpy(tmp_buf, name);
+		strscpy(tmp_buf, name);
 
-	n = prom_early_alloc(strlen(tmp_buf) + 1);
-	strcpy(n, tmp_buf);
+	n_sz = strlen(tmp_buf) + 1;
+	n = prom_early_alloc(n_sz);
+	strscpy(n, tmp_buf, n_sz);
 
 	return n;
 }
@@ -204,13 +206,14 @@ extern void restore_current(void);
 void __init of_console_init(void)
 {
 	char *msg = "OF stdout device is: %s\n";
+	const size_t of_console_path_sz = 256;
 	struct device_node *dp;
 	unsigned long flags;
 	const char *type;
 	phandle node;
 	int skip, tmp, fd;
 
-	of_console_path = prom_early_alloc(256);
+	of_console_path = prom_early_alloc(of_console_path_sz);
 
 	switch (prom_vers) {
 	case PROM_V0:
@@ -297,7 +300,7 @@ void __init of_console_init(void)
 				prom_printf("No stdout-path in root node.\n");
 				prom_halt();
 			}
-			strcpy(of_console_path, path);
+			strscpy(of_console_path, path, of_console_path_sz);
 		}
 		break;
 	}
Signature · 1 line
2.51.0
#7 lore raw

PATCH 7/8 sparc64: Replace deprecated strcpy with strscpy in build_path_component

In reply to Thorsten Blum

strcpy() is deprecated; use strscpy() instead.

No functional changes intended.

---
 arch/sparc/kernel/prom_64.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/sparc/kernel/prom_64.c +5 -3
index ba82884cb92a..aa4799cbb9c1 100644
@@ -361,14 +361,16 @@ char * __init build_path_component(struct device_node *dp)
 {
 	const char *name = of_get_property(dp, "name", NULL);
 	char tmp_buf[64], *n;
+	size_t n_sz;
 
 	tmp_buf[0] = '\0';
 	__build_path_component(dp, tmp_buf);
 	if (tmp_buf[0] == '\0')
-		strcpy(tmp_buf, name);
+		strscpy(tmp_buf, name);
 
-	n = prom_early_alloc(strlen(tmp_buf) + 1);
-	strcpy(n, tmp_buf);
+	n_sz = strlen(tmp_buf) + 1;
+	n = prom_early_alloc(n_sz);
+	strscpy(n, tmp_buf, n_sz);
 
 	return n;
 }
Signature · 1 line
2.51.0
#8 lore raw

PATCH 8/8 sparc: Replace deprecated strcpy with strscpy in handle_nextprop_quirks

In reply to Thorsten Blum

strcpy() is deprecated; use strscpy() instead.

No functional changes intended.

---
 arch/sparc/kernel/prom_common.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
arch/sparc/kernel/prom_common.c +5 -2
index c9ec70888a39..d258fd10db01 100644
@@ -120,11 +120,14 @@ EXPORT_SYMBOL(of_find_in_proplist);
  */
 static int __init handle_nextprop_quirks(char *buf, const char *name)
 {
-	if (!name || strlen(name) == 0)
+	size_t name_len;
+
+	name_len = name ? strlen(name) : 0;
+	if (name_len == 0)
 		return -1;
 
 #ifdef CONFIG_SPARC32
-	strcpy(buf, name);
+	strscpy(buf, name, name_len + 1);
 #endif
 	return 0;
 }
Signature · 1 line
2.51.0
Reviewed-by on v1 3/8
#3 lore raw

Re: [PATCH 3/8] sparc: floppy: Replace deprecated strcpy with strscpy in sun_floppy_init

In reply to Thorsten Blum
Quoted 3 lines · Thorsten Blum

strcpy() is deprecated; use strscpy() instead.

No functional changes intended.

Is this the only one place in floppy (arch) code?

The change itself LGTM,

Signature · 2 lines
With Best Regards,
Andy Shevchenko