Thread (10 messages) 10 messages, 6 authors, 2024-11-17

Re: [PATCH] powermac: Call of_node_put(bk_node) only once in pmac_has_backlight_type()

From: Christophe Leroy <hidden>
Date: 2024-10-02 20:43:54
Also in: kernel-janitors, lkml


Le 02/10/2024 à 22:02, Markus Elfring a écrit :
From: Markus Elfring <redacted>
Date: Wed, 2 Oct 2024 21:50:27 +0200

An of_node_put(bk_node) call was immediately used after a pointer check
for an of_get_property() call in this function implementation.
Thus call such a function only once instead directly before the check.
It seems pointless to perform a put immediately after a get. Shouldn't 
of_find_property() be used instead ? And then of_property_read_string() 
would probably be better.

Maybe you can even use of_property_match_string().
quoted hunk ↗ jump to hunk
This issue was transformed by using the Coccinelle software.

Signed-off-by: Markus Elfring <redacted>
---
  arch/powerpc/platforms/powermac/backlight.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/platforms/powermac/backlight.c b/arch/powerpc/platforms/powermac/backlight.c
index 12bc01353bd3..d3666595a62e 100644
--- a/arch/powerpc/platforms/powermac/backlight.c
+++ b/arch/powerpc/platforms/powermac/backlight.c
@@ -61,11 +61,9 @@ int pmac_has_backlight_type(const char *type)
  	if (bk_node) {
  		const char *prop = of_get_property(bk_node,
  				"backlight-control", NULL);
-		if (prop && strncmp(prop, type, strlen(type)) == 0) {
-			of_node_put(bk_node);
-			return 1;
-		}
  		of_node_put(bk_node);
+		if (prop && strncmp(prop, type, strlen(type)) == 0)
+			return 1;
  	}

  	return 0;
--
2.46.1
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help