powerpc: kernel: fix refcount leak in format_show()
PATCH v2 1/1 powerpc: kernel: fix refcount leak in format_show()
Refcount leak will happen when format_show returns failure in multiple cases. Unified management of of_node_put can fix this problem.
---
v2:
1. change the title and description information.
2. fix all possible refcount leak.
arch/powerpc/kernel/secvar-sysfs.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
arch/powerpc/kernel/secvar-sysfs.c +6 -3
@@ -26,15 +26,18 @@ static ssize_t format_show(struct kobject *kobj, struct kobj_attribute *attr,const char *format; node =of_find_compatible_node (NULL ,NULL ,"ibm,secvar-backend" ); -if (!of_device_is_available (node)) -return -ENODEV ; +if (!of_device_is_available (node)) { + rc = -ENODEV ; + goto out; + } rc =of_property_read_string (node,"format" , &format);if (rc) -return rc; + goto out; rc =sprintf (buf,"%s\n" , format); +out:of_node_put (node);return rc;
Signature · 1 line
2.25.1
Any further suggestions for this patch? guys.
Thanks.
Quoted 39 lines · Hangyu Hua
Refcount leak will happen when
format_showreturns failure in multiple cases. Unified management ofof_node_putcan fix this problem.Signed-off-by Hangyu Hua <[email protected]>---
v2:
1. change the title and description information.
2. fix all possible refcount leak.arch/powerpc/kernel/secvar-sysfs.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)arch/powerpc/kernel/secvar-sysfs.c +6
-3@@ -26,15 +26,18 @@ static ssize_t format_show(struct kobject *kobj, struct kobj_attribute *attr,const char *format; node =of_find_compatible_node (NULL ,NULL ,"ibm,secvar-backend" ); -if (!of_device_is_available (node)) -return -ENODEV ; +if (!of_device_is_available (node)) { + rc = -ENODEV ; + goto out; + } rc =of_property_read_string (node,"format" , &format);if (rc) -return rc; + goto out; rc =sprintf (buf,"%s\n" , format); +out:of_node_put (node);return rc;
Michael Ellerman
AppliedQuoted 4 lines · Hangyu Hua
Refcount leak will happen when
format_showreturns failure in multiple cases. Unified management ofof_node_putcan fix this problem.
Applied to powerpc/next.
[1/1] powerpc: kernel: fix refcount leak in format_show()
https://git.kernel.org/powerpc/c/d601fd24e6964967f115f036a840f4f28488f63f
cheers