Skip to contentSkip to conversation

powerpc/powernv: Avoid strlen() in pnv_restart()

PATCH Applied Thorsten Blum 3 participants 5 messages Jul 21 – Aug 3 PowerPC

lore
Share & tools
lore
#0 lore raw

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
index 06ed5e2aa265..2af92e7ba4ee 100644
@@ -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);
#1 lore raw

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
index 7faebcffc9df..18e3f1a036e3 100644
@@ -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);
reviewer Reviewed-by on v1 2/2
#2 lore raw

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().

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
index 7faebcffc9df..18e3f1a036e3 100644

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 -1
  		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')

Can use !*name instead.

Quoted 3 lines
arch/powerpc/platforms/pseries/reconfig.c +0 -0
  		return -ENODEV;
 
  	newprop = new_property(name, length, value, NULL);
reviewer Reviewed-by on v1 1/2
#3 lore raw
In reply to Thorsten Blum

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
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
index 06ed5e2aa265..2af92e7ba4ee 100644

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 -0
  			rc = opal_cec_reboot();
  		else if (strcmp(cmd, "full") == 0)
  			rc = opal_cec_reboot2(OPAL_REBOOT_FULL_IPL, NULL);
maintainer Applied
#4 lore raw
In reply to Thorsten Blum
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