ARM: OMAP2: use snprintf() in multiple check revision functions
Subsystems (3)
PATCH 1/4 ARM: OMAP2: use snprintf() in multiple check revision functions
Replace unbounded sprintf() calls with the safer snprintf() in multiple *_check_revision() functions.
Signed-off-by Thorsten Blum <[email protected]>
--- arch/arm/mach-omap2/id.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
arch/arm/mach-omap2/id.c +11 -11
@@ -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); }
PATCH 2/4 ARM: OMAP2: use sysfs_emit() in type_show
Replace unbounded sprintf() with sysfs_emit() in type_show().
Signed-off-by Thorsten Blum <[email protected]>
--- arch/arm/mach-omap2/id.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/mach-omap2/id.c +2 -1
@@ -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);
PATCH 3/4 ARM: OMAP2: clean up string copying and formatting in omap3_cpuinfo
In reply to Thorsten BlumReplace 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 <[email protected]>
--- arch/arm/mach-omap2/id.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/mach-omap2/id.c +2 -2
@@ -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); }
PATCH 4/4 ARM: OMAP2: zero-initialize local buffer in omap3_cpuinfo
In reply to Thorsten BlumRemove memset(0) and zero-initialize the local buffer instead.
Signed-off-by Thorsten Blum <[email protected]>
--- arch/arm/mach-omap2/id.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
arch/arm/mach-omap2/id.c +1 -3
@@ -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. *