The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Johan Hovold <johan@kernel.org>, cgel.zte@gmail.com
Cc: linux-kernel@vger.kernel.org,
	Minghao Chi <chi.minghao@zte.com.cn>,
	iommu@lists.linux-foundation.org, will@kernel.org,
	Zeal Robot <zealci@zte.com.cn>
Subject: Re: [PATCH] iommu/ipmmu-vmsa: Avoid leak OF node on error
Date: Mon, 23 May 2022 14:10:26 +0100	[thread overview]
Message-ID: <1c90b375-e738-95b3-6904-8c373a0b28d6@arm.com> (raw)
In-Reply-To: <Yot13L7XgvxTkgnE@hovoldconsulting.com>

On 2022-05-23 12:54, Johan Hovold wrote:
> On Mon, May 23, 2022 at 11:11:45AM +0000, cgel.zte@gmail.com wrote:
>> From: Minghao Chi <chi.minghao@zte.com.cn>
>>
>> The OF node should be put before returning error in ipmmu_init(),
>> otherwise node's refcount will be leaked.
>>
>> Reported-by: Zeal Robot <zealci@zte.com.cn>
>> Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
>> ---
>>   drivers/iommu/ipmmu-vmsa.c | 3 +--
>>   1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c
>> index 8fdb84b3642b..f6440b106f46 100644
>> --- a/drivers/iommu/ipmmu-vmsa.c
>> +++ b/drivers/iommu/ipmmu-vmsa.c
>> @@ -1179,11 +1179,10 @@ static int __init ipmmu_init(void)
>>   		return 0;
>>   
>>   	np = of_find_matching_node(NULL, ipmmu_of_ids);
>> +	of_node_put(np);
>>   	if (!np)
>>   		return 0;
>>   
>> -	of_node_put(np);
>> -
>>   	ret = platform_driver_register(&ipmmu_driver);
>>   	if (ret < 0)
>>   		return ret;
> 
> NAK

Indeed. How exactly can we hold a refcount on NULL, let alone leak it?

Static checkers are great for flagging up code that *might* have issues, 
but please actually *look* at the code and apply some thought before 
sending a patch.

Robin.

      reply	other threads:[~2022-05-23 13:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-23 11:11 [PATCH] iommu/ipmmu-vmsa: Avoid leak OF node on error cgel.zte
2022-05-23 11:54 ` Johan Hovold
2022-05-23 13:10   ` Robin Murphy [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=1c90b375-e738-95b3-6904-8c373a0b28d6@arm.com \
    --to=robin.murphy@arm.com \
    --cc=cgel.zte@gmail.com \
    --cc=chi.minghao@zte.com.cn \
    --cc=iommu@lists.linux-foundation.org \
    --cc=johan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=will@kernel.org \
    --cc=zealci@zte.com.cn \
    /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