powerpc/powernv: Avoid strlen() in pnv_restart()
PATCH 1/2 powerpc/powernv: Avoid strlen() in pnv_restart()
Check only the first byte instead of scanning the entire string with strlen().
--- arch/powerpc/platforms/powernv/setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/platforms/powernv/setup.c +1 -1
@@ -312,7 +312,7 @@ static void __noreturn pnv_restart(char *cmd)pnv_prepare_going_down (); do { - if (!cmd || !strlen(cmd)) + if (!cmd || *cmd == '\0') rc = opal_cec_reboot(); else if (strcmp(cmd, "full") == 0) rc = opal_cec_reboot2(OPAL_REBOOT_FULL_IPL, NULL);
PATCH 2/2 powerpc/pseries: Avoid strlen() in do_{remove,update}_property()
Check only the first byte instead of scanning the entire string with strlen().
--- arch/powerpc/platforms/pseries/reconfig.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/platforms/pseries/reconfig.c +2 -2
@@ -307,7 +307,7 @@ static int do_remove_property(char *buf, size_t bufsize)if (tmp) *tmp ='\0' ; -if (strlen (buf) ==0 ) +if (*buf =='\0' )return -EINVAL ;return of_remove_property (np,of_find_property (np, buf,NULL ));
@@ -330,7 +330,7 @@ static int do_update_property(char *buf, size_t bufsize)if (!next_prop)return -EINVAL ; -if (!strlen (name)) +if (*name =='\0' )return -ENODEV ; newprop =new_property (name, length, value,NULL );
Re: [PATCH 2/2] powerpc/pseries: Avoid strlen() in do_{remove,update}_property()
Le 21/07/2026 à 17:53, Thorsten Blum a écrit :
Quoted 4 lines
Check only the first byte instead of scanning the entire string with
strlen().Signed-off-by Thorsten Blum <[email protected]>
Quoted 9 lines
--- arch/powerpc/platforms/pseries/reconfig.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/powerpc/platforms/pseries/reconfig.c +0
-0
arch/powerpc/platforms/pseries/reconfig.c static int do_remove_property(char *buf, size_t bufsize) · line 310
Quoted 5 lines
arch/powerpc/platforms/pseries/reconfig.c +1
-1@@ -307,7 +307,7 @@ static int do_remove_property(char *buf, size_t bufsize)if (tmp) *tmp ='\0' ; -if (strlen (buf) ==0 ) +if (*buf =='\0' )
Can use !*buf instead.
arch/powerpc/platforms/pseries/reconfig.c static int do_update_property(char *buf, size_t bufsize) · line 333
Quoted 9 lines
arch/powerpc/platforms/pseries/reconfig.c +1
-1return -EINVAL ;return of_remove_property (np,of_find_property (np, buf,NULL ));@@ -330,7 +330,7 @@ static int do_update_property(char *buf, size_t bufsize)if (!next_prop)return -EINVAL ; -if (!strlen (name)) +if (*name =='\0' )
Can use !*name instead.
Quoted 3 lines
arch/powerpc/platforms/pseries/reconfig.c +0
-0return -ENODEV ; newprop =new_property (name, length, value,NULL );
Le 21/07/2026 à 17:53, Thorsten Blum a écrit :
Quoted 2 lines
Check only the first byte instead of scanning the entire string with
strlen().
Well, strlen() is not going to scan the entire string, it will break at first 0. But I agreed calling strlen() is not worth it.
Quoted 2 lines
Signed-off-by Thorsten Blum <[email protected]>
Quoted 9 lines
--- arch/powerpc/platforms/powernv/setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/powerpc/platforms/powernv/setup.c +0
-0
arch/powerpc/platforms/powernv/setup.c static void __noreturn pnv_restart(char *cmd) · line 315
Quoted 5 lines
arch/powerpc/platforms/powernv/setup.c +1
-1@@ -312,7 +312,7 @@ static void __noreturn pnv_restart(char *cmd)pnv_prepare_going_down (); do { - if (!cmd || !strlen(cmd)) + if (!cmd || *cmd == '\0')
Maybe !*cmd instead ?
Quoted 3 lines
arch/powerpc/platforms/powernv/setup.c +0
-0rc =opal_cec_reboot (); else if (strcmp(cmd, "full") == 0) rc =opal_cec_reboot2 (OPAL_REBOOT_FULL_IPL ,NULL );
Quoted 4 lines · Thorsten Blum
Check only the first byte instead of scanning the entire string with
strlen().
Applied to powerpc/next.
[1/2] powerpc/powernv: Avoid strlen() in pnv_restart()
https://git.kernel.org/powerpc/c/86bb4d74da626064136d30367d1b35372b8320fb [2/2] powerpc/pseries: Avoid strlen() in do_{remove,update}_property() https://git.kernel.org/powerpc/c/903cc6e45401d7f3821758901f229b0b59e4f27c
cheers