linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iommu/ipmmu-vmsa: Avoid leak OF node on error
@ 2022-05-23 11:11 cgel.zte
  2022-05-23 11:54 ` Johan Hovold
  0 siblings, 1 reply; 3+ messages in thread
From: cgel.zte @ 2022-05-23 11:11 UTC (permalink / raw)
  To: joro; +Cc: will, iommu, linux-kernel, Minghao Chi, Zeal Robot

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;
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] iommu/ipmmu-vmsa: Avoid leak OF node on error
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Johan Hovold @ 2022-05-23 11:54 UTC (permalink / raw)
  To: cgel.zte; +Cc: joro, will, iommu, linux-kernel, Minghao Chi, Zeal Robot

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] iommu/ipmmu-vmsa: Avoid leak OF node on error
  2022-05-23 11:54 ` Johan Hovold
@ 2022-05-23 13:10   ` Robin Murphy
  0 siblings, 0 replies; 3+ messages in thread
From: Robin Murphy @ 2022-05-23 13:10 UTC (permalink / raw)
  To: Johan Hovold, cgel.zte; +Cc: linux-kernel, Minghao Chi, iommu, will, Zeal Robot

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-05-23 13:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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).