Re: [PATCH] powerpc: kernel: fix a refcount leak in format_show()

From
Hangyu Hua <hidden>
Date
2022-03-02 01:34:14
Also in
lkml
Reply to
Tyrel Datwyler, 2022-03-01
Thanks. I will resubmit my patch latter.

On 2022/3/2 03:50, Tyrel Datwyler wrote:
On 3/1/22 04:55, Michael Ellerman wrote:
quoted
Hangyu Hua [off-list ref] writes:
quoted
node needs to be dropped when of_property_read_string fails. So an earlier call
to of_node_put is required here.
That's true but ...
quoted
diff --git a/arch/powerpc/kernel/secvar-sysfs.c b/arch/powerpc/kernel/secvar-sysfs.c
index a0a78aba2083..cd0fa7028d86 100644
--- a/arch/powerpc/kernel/secvar-sysfs.c
+++ b/arch/powerpc/kernel/secvar-sysfs.c
@@ -30,13 +30,12 @@ static ssize_t format_show(struct kobject *kobj, struct kobj_attribute *attr,
  		return -ENODEV;
There's also a reference leak there ^

So if you're going to touch this code I'd like you to fix both reference
leaks in a single patch please.

Having the error cases set rc and then goto "out" which does the
of_node_put() is the obvious solution I think.
update_kobj_size() in the same source file provides a good example of the
suggested solution.

-Tyrel
quoted
cheers
quoted
  	rc = of_property_read_string(node, "format", &format);
+	of_node_put(node);
  	if (rc)
  		return rc;
  
  	rc = sprintf(buf, "%s\n", format);
  
-	of_node_put(node);
-
  	return rc;
  }
  
-- 
2.25.1
Thread (4 messages) 4 messages, 3 authors, last reply 2022-03-02
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help