All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] amba: fix refcount underflow if amba_device_add() fails
@ 2022-05-24  2:51 ` Kefeng Wang
  0 siblings, 0 replies; 5+ messages in thread
From: Kefeng Wang @ 2022-05-24  2:51 UTC (permalink / raw)
  To: linux, linux-kernel, linux-arm-kernel; +Cc: robh, Kefeng Wang, Guenter Roeck

"ARM: 9192/1: amba: fix memory leak in amba_device_try_add()" leads
to a refcount underflow if amba_device_add() fails, which called by
of_amba_device_create(), the of_amba_device_create() already exists
the error handling, so amba_put_device() only need to be added into
amba_deferred_retry().

Reported-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 drivers/amba/bus.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 0e3ed5eb367b..0cb20324da16 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -493,13 +493,8 @@ static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
 		goto skip_probe;
 
 	ret = amba_read_periphid(dev);
-	if (ret) {
-		if (ret != -EPROBE_DEFER) {
-			amba_device_put(dev);
-			goto err_out;
-		}
+	if (ret)
 		goto err_release;
-	}
 
 skip_probe:
 	ret = device_add(&dev->dev);
@@ -546,6 +541,7 @@ static int amba_deferred_retry(void)
 			continue;
 
 		list_del_init(&ddev->node);
+		amba_device_put(ddev->dev);
 		kfree(ddev);
 	}
 
-- 
2.35.3


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

* [PATCH] amba: fix refcount underflow if amba_device_add() fails
@ 2022-05-24  2:51 ` Kefeng Wang
  0 siblings, 0 replies; 5+ messages in thread
From: Kefeng Wang @ 2022-05-24  2:51 UTC (permalink / raw)
  To: linux, linux-kernel, linux-arm-kernel; +Cc: robh, Kefeng Wang, Guenter Roeck

"ARM: 9192/1: amba: fix memory leak in amba_device_try_add()" leads
to a refcount underflow if amba_device_add() fails, which called by
of_amba_device_create(), the of_amba_device_create() already exists
the error handling, so amba_put_device() only need to be added into
amba_deferred_retry().

Reported-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 drivers/amba/bus.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 0e3ed5eb367b..0cb20324da16 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -493,13 +493,8 @@ static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
 		goto skip_probe;
 
 	ret = amba_read_periphid(dev);
-	if (ret) {
-		if (ret != -EPROBE_DEFER) {
-			amba_device_put(dev);
-			goto err_out;
-		}
+	if (ret)
 		goto err_release;
-	}
 
 skip_probe:
 	ret = device_add(&dev->dev);
@@ -546,6 +541,7 @@ static int amba_deferred_retry(void)
 			continue;
 
 		list_del_init(&ddev->node);
+		amba_device_put(ddev->dev);
 		kfree(ddev);
 	}
 
-- 
2.35.3


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] amba: fix refcount underflow if amba_device_add() fails
  2022-05-24  3:09 Guenter Roeck
@ 2022-05-24  3:15   ` Kefeng Wang
  0 siblings, 0 replies; 5+ messages in thread
From: Kefeng Wang @ 2022-05-24  3:15 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: linux, linux-kernel, linux-arm-kernel, robh


On 2022/5/24 11:09, Guenter Roeck wrote:
> On Tue, May 24, 2022 at 10:51:39AM +0800, Kefeng Wang wrote:
>> "ARM: 9192/1: amba: fix memory leak in amba_device_try_add()" leads
>> to a refcount underflow if amba_device_add() fails, which called by
>> of_amba_device_create(), the of_amba_device_create() already exists
>> the error handling, so amba_put_device() only need to be added into
>> amba_deferred_retry().
>>
>> Reported-by: Guenter Roeck <linux@roeck-us.net>
>> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> Tested-by: Guenter Roeck <linux@roeck-us.net>

Thanks.

PS: I also test with kmemleak, this could also fix previous memory leak 
issue.

>
> Thanks,
> Guenter
>
>> ---
>>   drivers/amba/bus.c | 8 ++------
>>   1 file changed, 2 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
>> index 0e3ed5eb367b..0cb20324da16 100644
>> --- a/drivers/amba/bus.c
>> +++ b/drivers/amba/bus.c
>> @@ -493,13 +493,8 @@ static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
>>   		goto skip_probe;
>>   
>>   	ret = amba_read_periphid(dev);
>> -	if (ret) {
>> -		if (ret != -EPROBE_DEFER) {
>> -			amba_device_put(dev);
>> -			goto err_out;
>> -		}
>> +	if (ret)
>>   		goto err_release;
>> -	}
>>   
>>   skip_probe:
>>   	ret = device_add(&dev->dev);
>> @@ -546,6 +541,7 @@ static int amba_deferred_retry(void)
>>   			continue;
>>   
>>   		list_del_init(&ddev->node);
>> +		amba_device_put(ddev->dev);
>>   		kfree(ddev);
>>   	}
>>   
>> -- 
>> 2.35.3
>>
> .

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

* Re: [PATCH] amba: fix refcount underflow if amba_device_add() fails
@ 2022-05-24  3:15   ` Kefeng Wang
  0 siblings, 0 replies; 5+ messages in thread
From: Kefeng Wang @ 2022-05-24  3:15 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: linux, linux-kernel, linux-arm-kernel, robh


On 2022/5/24 11:09, Guenter Roeck wrote:
> On Tue, May 24, 2022 at 10:51:39AM +0800, Kefeng Wang wrote:
>> "ARM: 9192/1: amba: fix memory leak in amba_device_try_add()" leads
>> to a refcount underflow if amba_device_add() fails, which called by
>> of_amba_device_create(), the of_amba_device_create() already exists
>> the error handling, so amba_put_device() only need to be added into
>> amba_deferred_retry().
>>
>> Reported-by: Guenter Roeck <linux@roeck-us.net>
>> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> Tested-by: Guenter Roeck <linux@roeck-us.net>

Thanks.

PS: I also test with kmemleak, this could also fix previous memory leak 
issue.

>
> Thanks,
> Guenter
>
>> ---
>>   drivers/amba/bus.c | 8 ++------
>>   1 file changed, 2 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
>> index 0e3ed5eb367b..0cb20324da16 100644
>> --- a/drivers/amba/bus.c
>> +++ b/drivers/amba/bus.c
>> @@ -493,13 +493,8 @@ static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
>>   		goto skip_probe;
>>   
>>   	ret = amba_read_periphid(dev);
>> -	if (ret) {
>> -		if (ret != -EPROBE_DEFER) {
>> -			amba_device_put(dev);
>> -			goto err_out;
>> -		}
>> +	if (ret)
>>   		goto err_release;
>> -	}
>>   
>>   skip_probe:
>>   	ret = device_add(&dev->dev);
>> @@ -546,6 +541,7 @@ static int amba_deferred_retry(void)
>>   			continue;
>>   
>>   		list_del_init(&ddev->node);
>> +		amba_device_put(ddev->dev);
>>   		kfree(ddev);
>>   	}
>>   
>> -- 
>> 2.35.3
>>
> .

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] amba: fix refcount underflow if amba_device_add() fails
@ 2022-05-24  3:09 Guenter Roeck
  2022-05-24  3:15   ` Kefeng Wang
  0 siblings, 1 reply; 5+ messages in thread
From: Guenter Roeck @ 2022-05-24  3:09 UTC (permalink / raw)
  To: Kefeng Wang; +Cc: linux, linux-kernel, linux-arm-kernel, robh

On Tue, May 24, 2022 at 10:51:39AM +0800, Kefeng Wang wrote:
> "ARM: 9192/1: amba: fix memory leak in amba_device_try_add()" leads
> to a refcount underflow if amba_device_add() fails, which called by
> of_amba_device_create(), the of_amba_device_create() already exists
> the error handling, so amba_put_device() only need to be added into
> amba_deferred_retry().
> 
> Reported-by: Guenter Roeck <linux@roeck-us.net>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>

Tested-by: Guenter Roeck <linux@roeck-us.net>

Thanks,
Guenter

> ---
>  drivers/amba/bus.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
> index 0e3ed5eb367b..0cb20324da16 100644
> --- a/drivers/amba/bus.c
> +++ b/drivers/amba/bus.c
> @@ -493,13 +493,8 @@ static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
>  		goto skip_probe;
>  
>  	ret = amba_read_periphid(dev);
> -	if (ret) {
> -		if (ret != -EPROBE_DEFER) {
> -			amba_device_put(dev);
> -			goto err_out;
> -		}
> +	if (ret)
>  		goto err_release;
> -	}
>  
>  skip_probe:
>  	ret = device_add(&dev->dev);
> @@ -546,6 +541,7 @@ static int amba_deferred_retry(void)
>  			continue;
>  
>  		list_del_init(&ddev->node);
> +		amba_device_put(ddev->dev);
>  		kfree(ddev);
>  	}
>  
> -- 
> 2.35.3
> 

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

end of thread, other threads:[~2022-05-24  3:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-24  2:51 [PATCH] amba: fix refcount underflow if amba_device_add() fails Kefeng Wang
2022-05-24  2:51 ` Kefeng Wang
2022-05-24  3:09 Guenter Roeck
2022-05-24  3:15 ` Kefeng Wang
2022-05-24  3:15   ` Kefeng Wang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.