linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Hangyu Hua <hbh25y@gmail.com>
To: Tyrel Datwyler <tyreld@linux.ibm.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	benh@kernel.crashing.org, paulus@samba.org
Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] powerpc: kernel: fix a refcount leak in format_show()
Date: Wed, 2 Mar 2022 09:34:02 +0800	[thread overview]
Message-ID: <43e1dba5-2af7-658b-ae45-c7a6c1c0dc6d@gmail.com> (raw)
In-Reply-To: <825f5cba-a62b-a691-225e-22f6bb9b10a8@linux.ibm.com>

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
> 

      reply	other threads:[~2022-03-02  1:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=43e1dba5-2af7-658b-ae45-c7a6c1c0dc6d@gmail.com \
    --to=hbh25y@gmail.com \
    --cc=benh@kernel.crashing.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    --cc=tyreld@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).