public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH 1/4] ARM: OMAP2: use snprintf() in multiple check revision functions
@ 2026-04-23 17:10 Thorsten Blum
  2026-04-23 17:10 ` [PATCH 2/4] ARM: OMAP2: use sysfs_emit() in type_show Thorsten Blum
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Thorsten Blum @ 2026-04-23 17:10 UTC (permalink / raw)
  To: Aaro Koskinen, Andreas Kemnade, Kevin Hilman, Roger Quadros,
	Tony Lindgren, Russell King
  Cc: Thorsten Blum, linux-arm-kernel, linux-omap, linux-kernel

Replace unbounded sprintf() calls with the safer snprintf() in multiple
*_check_revision() functions.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 arch/arm/mach-omap2/id.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/arch/arm/mach-omap2/id.c b/arch/arm/mach-omap2/id.c
index cf2bfb447ee2..44d7471666a8 100644
--- a/arch/arm/mach-omap2/id.c
+++ b/arch/arm/mach-omap2/id.c
@@ -192,8 +192,8 @@ void __init omap2xxx_check_revision(void)
 		j = i;
 	}
 
-	sprintf(soc_name, "OMAP%04x", omap_rev() >> 16);
-	sprintf(soc_rev, "ES%x", (omap_rev() >> 12) & 0xf);
+	snprintf(soc_name, sizeof(soc_name), "OMAP%04x", omap_rev() >> 16);
+	snprintf(soc_rev, sizeof(soc_rev), "ES%x", (omap_rev() >> 12) & 0xf);
 
 	pr_info("%s", soc_name);
 	if ((omap_rev() >> 8) & 0x0f)
@@ -519,7 +519,7 @@ void __init omap3xxx_check_revision(void)
 		pr_warn("Warning: unknown chip type: hawkeye %04x, assuming OMAP3630ES1.2\n",
 			hawkeye);
 	}
-	sprintf(soc_rev, "ES%s", cpu_rev);
+	snprintf(soc_rev, sizeof(soc_rev), "ES%s", cpu_rev);
 }
 
 void __init omap4xxx_check_revision(void)
@@ -594,9 +594,9 @@ void __init omap4xxx_check_revision(void)
 		omap_revision = OMAP4430_REV_ES2_3;
 	}
 
-	sprintf(soc_name, "OMAP%04x", omap_rev() >> 16);
-	sprintf(soc_rev, "ES%d.%d", (omap_rev() >> 12) & 0xf,
-						(omap_rev() >> 8) & 0xf);
+	snprintf(soc_name, sizeof(soc_name), "OMAP%04x", omap_rev() >> 16);
+	snprintf(soc_rev, sizeof(soc_rev), "ES%d.%d", (omap_rev() >> 12) & 0xf,
+		 (omap_rev() >> 8) & 0xf);
 	pr_info("%s %s\n", soc_name, soc_rev);
 }
 
@@ -637,8 +637,8 @@ void __init omap5xxx_check_revision(void)
 		omap_revision = OMAP5430_REV_ES2_0;
 	}
 
-	sprintf(soc_name, "OMAP%04x", omap_rev() >> 16);
-	sprintf(soc_rev, "ES%d.0", (omap_rev() >> 12) & 0xf);
+	snprintf(soc_name, sizeof(soc_name), "OMAP%04x", omap_rev() >> 16);
+	snprintf(soc_rev, sizeof(soc_rev), "ES%d.0", (omap_rev() >> 12) & 0xf);
 
 	pr_info("%s %s\n", soc_name, soc_rev);
 }
@@ -712,9 +712,9 @@ void __init dra7xxx_check_revision(void)
 		omap_revision = DRA752_REV_ES2_0;
 	}
 
-	sprintf(soc_name, "DRA%03x", omap_rev() >> 16);
-	sprintf(soc_rev, "ES%d.%d", (omap_rev() >> 12) & 0xf,
-		(omap_rev() >> 8) & 0xf);
+	snprintf(soc_name, sizeof(soc_name), "DRA%03x", omap_rev() >> 16);
+	snprintf(soc_rev, sizeof(soc_rev), "ES%d.%d", (omap_rev() >> 12) & 0xf,
+		 (omap_rev() >> 8) & 0xf);
 
 	pr_info("%s %s\n", soc_name, soc_rev);
 }


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

* [PATCH 2/4] ARM: OMAP2: use sysfs_emit() in type_show
  2026-04-23 17:10 [PATCH 1/4] ARM: OMAP2: use snprintf() in multiple check revision functions Thorsten Blum
@ 2026-04-23 17:10 ` Thorsten Blum
  2026-04-23 17:10 ` [PATCH 3/4] ARM: OMAP2: clean up string copying and formatting in omap3_cpuinfo Thorsten Blum
  2026-04-23 17:10 ` [PATCH 4/4] ARM: OMAP2: zero-initialize local buffer " Thorsten Blum
  2 siblings, 0 replies; 4+ messages in thread
From: Thorsten Blum @ 2026-04-23 17:10 UTC (permalink / raw)
  To: Aaro Koskinen, Andreas Kemnade, Kevin Hilman, Roger Quadros,
	Tony Lindgren, Russell King
  Cc: Thorsten Blum, linux-omap, linux-arm-kernel, linux-kernel

Replace unbounded sprintf() with sysfs_emit() in type_show().

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 arch/arm/mach-omap2/id.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-omap2/id.c b/arch/arm/mach-omap2/id.c
index 44d7471666a8..25ded74e4b01 100644
--- a/arch/arm/mach-omap2/id.c
+++ b/arch/arm/mach-omap2/id.c
@@ -18,6 +18,7 @@
 #include <linux/random.h>
 #include <linux/slab.h>
 #include <linux/string.h>
+#include <linux/sysfs.h>
 
 #ifdef CONFIG_SOC_BUS
 #include <linux/sys_soc.h>
@@ -771,7 +772,7 @@ static const char * __init omap_get_family(void)
 static ssize_t
 type_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
-	return sprintf(buf, "%s\n", omap_types[omap_type()]);
+	return sysfs_emit(buf, "%s\n", omap_types[omap_type()]);
 }
 
 static DEVICE_ATTR_RO(type);


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

* [PATCH 3/4] ARM: OMAP2: clean up string copying and formatting in omap3_cpuinfo
  2026-04-23 17:10 [PATCH 1/4] ARM: OMAP2: use snprintf() in multiple check revision functions Thorsten Blum
  2026-04-23 17:10 ` [PATCH 2/4] ARM: OMAP2: use sysfs_emit() in type_show Thorsten Blum
@ 2026-04-23 17:10 ` Thorsten Blum
  2026-04-23 17:10 ` [PATCH 4/4] ARM: OMAP2: zero-initialize local buffer " Thorsten Blum
  2 siblings, 0 replies; 4+ messages in thread
From: Thorsten Blum @ 2026-04-23 17:10 UTC (permalink / raw)
  To: Aaro Koskinen, Andreas Kemnade, Kevin Hilman, Roger Quadros,
	Tony Lindgren, Russell King
  Cc: Thorsten Blum, linux-arm-kernel, linux-omap, linux-kernel

Replace scnprintf("%s") with the faster and more direct strscpy().

Remove unnecessary and inconsistent 'n' arithmetic when 'n = 0', and
when 'n' is no longer used at the end of the function.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 arch/arm/mach-omap2/id.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-omap2/id.c b/arch/arm/mach-omap2/id.c
index 25ded74e4b01..126ffd87f572 100644
--- a/arch/arm/mach-omap2/id.c
+++ b/arch/arm/mach-omap2/id.c
@@ -255,7 +255,7 @@ static void __init omap3_cpuinfo(void)
 	strscpy(soc_name, cpu_name);
 
 	/* Print verbose information */
-	n += scnprintf(buf, sizeof(buf) - n, "%s %s (", soc_name, soc_rev);
+	n += scnprintf(buf, sizeof(buf), "%s %s (", soc_name, soc_rev);
 
 	OMAP3_SHOW_FEATURE(l2cache);
 	OMAP3_SHOW_FEATURE(iva);
@@ -265,7 +265,7 @@ static void __init omap3_cpuinfo(void)
 	OMAP3_SHOW_FEATURE(192mhz_clk);
 	if (*(buf + n - 1) == ' ')
 		n--;
-	n += scnprintf(buf + n, sizeof(buf) - n, ")\n");
+	scnprintf(buf + n, sizeof(buf) - n, ")\n");
 	pr_info("%s", buf);
 }
 


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

* [PATCH 4/4] ARM: OMAP2: zero-initialize local buffer in omap3_cpuinfo
  2026-04-23 17:10 [PATCH 1/4] ARM: OMAP2: use snprintf() in multiple check revision functions Thorsten Blum
  2026-04-23 17:10 ` [PATCH 2/4] ARM: OMAP2: use sysfs_emit() in type_show Thorsten Blum
  2026-04-23 17:10 ` [PATCH 3/4] ARM: OMAP2: clean up string copying and formatting in omap3_cpuinfo Thorsten Blum
@ 2026-04-23 17:10 ` Thorsten Blum
  2 siblings, 0 replies; 4+ messages in thread
From: Thorsten Blum @ 2026-04-23 17:10 UTC (permalink / raw)
  To: Aaro Koskinen, Andreas Kemnade, Kevin Hilman, Roger Quadros,
	Tony Lindgren, Russell King
  Cc: Thorsten Blum, linux-arm-kernel, linux-omap, linux-kernel

Remove memset(0) and zero-initialize the local buffer instead.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 arch/arm/mach-omap2/id.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/arm/mach-omap2/id.c b/arch/arm/mach-omap2/id.c
index 126ffd87f572..9a10e96e65e3 100644
--- a/arch/arm/mach-omap2/id.c
+++ b/arch/arm/mach-omap2/id.c
@@ -209,11 +209,9 @@ void __init omap2xxx_check_revision(void)
 static void __init omap3_cpuinfo(void)
 {
 	const char *cpu_name;
-	char buf[64];
+	char buf[64] = { 0 };
 	int n = 0;
 
-	memset(buf, 0, sizeof(buf));
-
 	/*
 	 * OMAP3430 and OMAP3530 are assumed to be same.
 	 *


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

end of thread, other threads:[~2026-04-23 17:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-23 17:10 [PATCH 1/4] ARM: OMAP2: use snprintf() in multiple check revision functions Thorsten Blum
2026-04-23 17:10 ` [PATCH 2/4] ARM: OMAP2: use sysfs_emit() in type_show Thorsten Blum
2026-04-23 17:10 ` [PATCH 3/4] ARM: OMAP2: clean up string copying and formatting in omap3_cpuinfo Thorsten Blum
2026-04-23 17:10 ` [PATCH 4/4] ARM: OMAP2: zero-initialize local buffer " Thorsten Blum

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