powerpc/dt_cpu_ftrs: Avoid separate strlen() in scan_callback()
PATCH v2 1/1 powerpc/dt_cpu_ftrs: Avoid separate strlen() in scan_callback()
Check only the first byte instead of scanning the entire string with strlen(). While at it, keep dt_cpu_name static, but move it into dt_cpu_ftrs_scan_callback(), where it is assigned.
Signed-off-by Thorsten Blum <[email protected]>
---
Changes in v2:
- Check only the first byte since strscpy() copies empty strings (David)
- v1: https://lore.kernel.org/lkml/[email protected]/
--- arch/powerpc/kernel/dt_cpu_ftrs.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
arch/powerpc/kernel/dt_cpu_ftrs.c +3 -4
@@ -90,8 +90,6 @@ static void __restore_cpu_cpufeatures(void)init_pmu_registers (); } -static char dt_cpu_name[64 ]; -static struct cpu_spec __initdata base_cpu_spec = { .cpu_name =NULL , .cpu_features =CPU_FTRS_DT_CPU_BASE ,
@@ -1069,6 +1067,7 @@ static int __init count_cpufeatures_subnodes(unsigned long node,static int __init dt_cpu_ftrs_scan_callback (unsigned long node,const char *uname,int depth,void *data) { +static char dt_cpu_name[64 ];const __be32 *prop;int count, i;u32 isa;
@@ -1106,8 +1105,8 @@ static int __init dt_cpu_ftrs_scan_callback(unsigned long node, const char } prop =of_get_flat_dt_prop (node,"display-name" ,NULL ); -if (prop &&strlen ((char *)prop) !=0 ) { -strscpy (dt_cpu_name, (char *)prop,sizeof (dt_cpu_name)); +if (prop && *(char *)prop !=0 ) { +strscpy (dt_cpu_name, (char *)prop); cur_cpu_spec->cpu_name = dt_cpu_name; }
Quoted 5 lines · Thorsten Blum
Check only the first byte instead of scanning the entire string with
strlen(). While at it, keepdt_cpu_namestatic, but move it intodt_cpu_ftrs_scan_callback(), where it is assigned.
Applied to powerpc/next.
[1/1] powerpc/dt_cpu_ftrs: Avoid separate strlen() in scan_callback()
https://git.kernel.org/powerpc/c/b6cfbfd6b2992e3f34d255c983dc9f20ef0f5cd8
cheers