powerpc: kernel: fix a refcount leak in format_show()
PATCH 1/1 powerpc: kernel: fix a refcount leak in format_show()
node needs to be dropped when of_property_read_string fails. So an earlier call to of_node_put is required here.
--- arch/powerpc/kernel/secvar-sysfs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/powerpc/kernel/secvar-sysfs.c +1 -2
@@ -30,13 +30,12 @@ static ssize_t format_show(struct kobject *kobj, struct kobj_attribute *attr,return -ENODEV ; 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; }
Signature · 1 line
2.25.1
Michael Ellerman
reviewerQuoted 2 lines · Hangyu Hua
node needs to be dropped when
of_property_read_stringfails. So an earlier call toof_node_putis required here.
That's true but ...
arch/powerpc/kernel/secvar-sysfs.c static ssize_t format_show(struct kobject *kobj, struct kobj_attribute *attr, · line 30
Quoted 6 lines
arch/powerpc/kernel/secvar-sysfs.c +0
-0@@ -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.
cheers
Quoted 14 lines
arch/powerpc/kernel/secvar-sysfs.c +1
-2rc =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; }Signature · 1 line
2.25.1
Quoted 15 lines · Michael Ellerman
Quoted 2 lines · Hangyu Hua
node needs to be dropped when
of_property_read_stringfails. So an earlier call toof_node_putis required here.That's true but ...
arch/powerpc/kernel/secvar-sysfs.c static ssize_t format_show(struct kobject *kobj, struct kobj_attribute *attr, · line 30
Quoted 6 lines
arch/powerpc/kernel/secvar-sysfs.c +0
-0@@ -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 ^
Quoted 5 lines
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 17 lines
cheers
Quoted 14 lines
arch/powerpc/kernel/secvar-sysfs.c +1
-2rc =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; }Signature · 1 line
2.25.1
Thanks. I will resubmit my patch latter.
Quoted 45 lines · Tyrel Datwyler
Quoted 15 lines · Michael Ellerman
Quoted 2 lines · Hangyu Hua
node needs to be dropped when
of_property_read_stringfails. So an earlier call toof_node_putis required here.That's true but ...
arch/powerpc/kernel/secvar-sysfs.c static ssize_t format_show(struct kobject *kobj, struct kobj_attribute *attr, · line 30
Quoted 6 lines
arch/powerpc/kernel/secvar-sysfs.c +0
-0@@ -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 ^
Quoted 5 lines
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 17 lines
cheers
Quoted 14 lines
arch/powerpc/kernel/secvar-sysfs.c +1
-2rc =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; }Signature · 1 line
2.25.1