* [PATCH] powerpc: kernel: fix a refcount leak in format_show()
@ 2022-02-28 9:11 Hangyu Hua
2022-03-01 12:55 ` Michael Ellerman
0 siblings, 1 reply; 4+ messages in thread
From: Hangyu Hua @ 2022-02-28 9:11 UTC (permalink / raw)
To: mpe, benh, paulus; +Cc: linuxppc-dev, linux-kernel, Hangyu Hua
node needs to be dropped when of_property_read_string fails. So an earlier call
to of_node_put is required here.
Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
---
arch/powerpc/kernel/secvar-sysfs.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
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;
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] powerpc: kernel: fix a refcount leak in format_show()
2022-02-28 9:11 [PATCH] powerpc: kernel: fix a refcount leak in format_show() Hangyu Hua
@ 2022-03-01 12:55 ` Michael Ellerman
2022-03-01 19:50 ` Tyrel Datwyler
0 siblings, 1 reply; 4+ messages in thread
From: Michael Ellerman @ 2022-03-01 12:55 UTC (permalink / raw)
To: Hangyu Hua, benh, paulus; +Cc: linuxppc-dev, linux-kernel, Hangyu Hua
Hangyu Hua <hbh25y@gmail.com> writes:
> 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 ...
> 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.
cheers
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] powerpc: kernel: fix a refcount leak in format_show()
2022-03-01 12:55 ` Michael Ellerman
@ 2022-03-01 19:50 ` Tyrel Datwyler
2022-03-02 1:34 ` Hangyu Hua
0 siblings, 1 reply; 4+ messages in thread
From: Tyrel Datwyler @ 2022-03-01 19:50 UTC (permalink / raw)
To: Michael Ellerman, Hangyu Hua, benh, paulus; +Cc: linuxppc-dev, linux-kernel
On 3/1/22 04:55, Michael Ellerman wrote:
> Hangyu Hua <hbh25y@gmail.com> writes:
>> 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 ...
>
>> 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
>
> cheers
>
>> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] powerpc: kernel: fix a refcount leak in format_show()
2022-03-01 19:50 ` Tyrel Datwyler
@ 2022-03-02 1:34 ` Hangyu Hua
0 siblings, 0 replies; 4+ messages in thread
From: Hangyu Hua @ 2022-03-02 1:34 UTC (permalink / raw)
To: Tyrel Datwyler, Michael Ellerman, benh, paulus; +Cc: linuxppc-dev, linux-kernel
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:
>> Hangyu Hua <hbh25y@gmail.com> writes:
>>> 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 ...
>>
>>> 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
>
>>
>> cheers
>>
>>> 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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-03-02 1:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-28 9:11 [PATCH] powerpc: kernel: fix a refcount leak in format_show() Hangyu Hua
2022-03-01 12:55 ` Michael Ellerman
2022-03-01 19:50 ` Tyrel Datwyler
2022-03-02 1:34 ` Hangyu Hua
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).