Skip to contentSkip to conversation

nios2: Replace strcpy() with strscpy() and simplify setup_cpuinfo()

PATCH Superseded Thorsten Blum 2 participants 2 messages Apr 16, 2025 NIOS2 architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nios2: Replace strcpy() with strscpy() and simplify setup_cpuinfo()

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

Since the destination buffer has a fixed length, strscpy() automatically determines its size using sizeof() when the size argument is omitted. This makes the explicit size argument unnecessary - remove it.

Now, combine both if-else branches using strscpy() and the same buffer into a single statement to simplify the code.

No functional changes intended.

---
 arch/nios2/kernel/cpuinfo.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
arch/nios2/kernel/cpuinfo.c +1 -4
index 7b1e8f9128e9..55882feb6249 100644
@@ -46,10 +46,7 @@ void __init setup_cpuinfo(void)
 	cpuinfo.cpu_clock_freq = fcpu(cpu, "clock-frequency");
 
 	str = of_get_property(cpu, "altr,implementation", &len);
-	if (str)
-		strscpy(cpuinfo.cpu_impl, str, sizeof(cpuinfo.cpu_impl));
-	else
-		strcpy(cpuinfo.cpu_impl, "<unknown>");
+	strscpy(cpuinfo.cpu_impl, str ?: "<unknown>");
 
 	cpuinfo.has_div = of_property_read_bool(cpu, "altr,has-div");
 	cpuinfo.has_mul = of_property_read_bool(cpu, "altr,has-mul");
Signature · 1 line
2.49.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Thorsten Blum

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

Since the destination buffer has a fixed length, strscpy() automatically determines its size using sizeof() when the size argument is omitted. This makes the explicit size argument unnecessary - remove it.

Quoted 8 lines

Now, combine both if-else branches using strscpy() and the same buffer into a single statement to simplify the code.

No functional changes intended.

Signature · 1 line
Kees Cook