All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bus: hisi_lpc: fix missing platform_device_put() in hisi_lpc_acpi_probe()
@ 2022-07-01  9:43 Yang Yingliang
  2022-07-04  8:01 ` John Garry
  0 siblings, 1 reply; 3+ messages in thread
From: Yang Yingliang @ 2022-07-01  9:43 UTC (permalink / raw)
  To: linux-kernel, john.garry

In error case in hisi_lpc_acpi_probe() after calling platform_device_add(),
hisi_lpc_acpi_remove() can't release the failed 'pdev', so it will be leak,
call platform_device_put() to fix this problem.
I'v constructed this error case and tested this patch on D05 board.

Fixes: 99c0228d6ff1 ("HISI LPC: Re-Add ACPI child enumeration support")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/bus/hisi_lpc.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/bus/hisi_lpc.c b/drivers/bus/hisi_lpc.c
index 378f5d62a991..e7eaa8784fee 100644
--- a/drivers/bus/hisi_lpc.c
+++ b/drivers/bus/hisi_lpc.c
@@ -503,13 +503,13 @@ static int hisi_lpc_acpi_probe(struct device *hostdev)
 {
 	struct acpi_device *adev = ACPI_COMPANION(hostdev);
 	struct acpi_device *child;
+	struct platform_device *pdev;
 	int ret;
 
 	/* Only consider the children of the host */
 	list_for_each_entry(child, &adev->children, node) {
 		const char *hid = acpi_device_hid(child);
 		const struct hisi_lpc_acpi_cell *cell;
-		struct platform_device *pdev;
 		const struct resource *res;
 		bool found = false;
 		int num_res;
@@ -571,22 +571,24 @@ static int hisi_lpc_acpi_probe(struct device *hostdev)
 
 		ret = platform_device_add_resources(pdev, res, num_res);
 		if (ret)
-			goto fail;
+			goto fail_put_device;
 
 		ret = platform_device_add_data(pdev, cell->pdata,
 					       cell->pdata_size);
 		if (ret)
-			goto fail;
+			goto fail_put_device;
 
 		ret = platform_device_add(pdev);
 		if (ret)
-			goto fail;
+			goto fail_put_device;
 
 		acpi_device_set_enumerated(child);
 	}
 
 	return 0;
 
+fail_put_device:
+	platform_device_put(pdev);
 fail:
 	hisi_lpc_acpi_remove(hostdev);
 	return ret;
-- 
2.25.1


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

* Re: [PATCH] bus: hisi_lpc: fix missing platform_device_put() in hisi_lpc_acpi_probe()
  2022-07-01  9:43 [PATCH] bus: hisi_lpc: fix missing platform_device_put() in hisi_lpc_acpi_probe() Yang Yingliang
@ 2022-07-04  8:01 ` John Garry
  2022-07-04  9:11   ` Yang Yingliang
  0 siblings, 1 reply; 3+ messages in thread
From: John Garry @ 2022-07-04  8:01 UTC (permalink / raw)
  To: Yang Yingliang, linux-kernel
  Cc: andriy.shevchenko@linux.intel.com >> Andy Shevchenko,
	Greg Kroah-Hartman, Rafael J. Wysocki

On 01/07/2022 10:43, Yang Yingliang wrote:

+

Please send any updated version cc'ing Rafael, who kindly offered to 
pick up this patch

> In error case in hisi_lpc_acpi_probe() after calling platform_device_add(),
> hisi_lpc_acpi_remove() can't release the failed 'pdev', so it will be leak,
> call platform_device_put() to fix this problem.
> I'v constructed this error case and tested this patch on D05 board.
> 
> Fixes: 99c0228d6ff1 ("HISI LPC: Re-Add ACPI child enumeration support")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
>   drivers/bus/hisi_lpc.c | 10 ++++++----
>   1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/bus/hisi_lpc.c b/drivers/bus/hisi_lpc.c
> index 378f5d62a991..e7eaa8784fee 100644
> --- a/drivers/bus/hisi_lpc.c
> +++ b/drivers/bus/hisi_lpc.c
> @@ -503,13 +503,13 @@ static int hisi_lpc_acpi_probe(struct device *hostdev)
>   {
>   	struct acpi_device *adev = ACPI_COMPANION(hostdev);
>   	struct acpi_device *child;
> +	struct platform_device *pdev;

nit: please maintain reverse-firtree ordering

>   	int ret;
>   
>   	/* Only consider the children of the host */
>   	list_for_each_entry(child, &adev->children, node) {
>   		const char *hid = acpi_device_hid(child);
>   		const struct hisi_lpc_acpi_cell *cell;
> -		struct platform_device *pdev;
>   		const struct resource *res;
>   		bool found = false;
>   		int num_res;
> @@ -571,22 +571,24 @@ static int hisi_lpc_acpi_probe(struct device *hostdev)
>   
>   		ret = platform_device_add_resources(pdev, res, num_res);
>   		if (ret)
> -			goto fail;
> +			goto fail_put_device;
>   
>   		ret = platform_device_add_data(pdev, cell->pdata,
>   					       cell->pdata_size);
>   		if (ret)
> -			goto fail;
> +			goto fail_put_device;
>   
>   		ret = platform_device_add(pdev);
>   		if (ret)
> -			goto fail;
> +			goto fail_put_device;
>   
>   		acpi_device_set_enumerated(child);
>   	}
>   
>   	return 0;
>   
> +fail_put_device:
> +	platform_device_put(pdev);

is this enough? As I see, this invokes platform_device_release(), but we 
would still need platform_device_del() to drop the pdev resources. 
hisi_lpc_acpi_remove_subdev() calls platform_device_unregister(), so it 
seems proper to do that here also. Please check it.

Thanks,
John

>   fail:
>   	hisi_lpc_acpi_remove(hostdev);
>   	return ret;


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

* Re: [PATCH] bus: hisi_lpc: fix missing platform_device_put() in hisi_lpc_acpi_probe()
  2022-07-04  8:01 ` John Garry
@ 2022-07-04  9:11   ` Yang Yingliang
  0 siblings, 0 replies; 3+ messages in thread
From: Yang Yingliang @ 2022-07-04  9:11 UTC (permalink / raw)
  To: John Garry, linux-kernel
  Cc: andriy.shevchenko, Greg Kroah-Hartman, Rafael J. Wysocki


On 2022/7/4 16:01, John Garry wrote:
> On 01/07/2022 10:43, Yang Yingliang wrote:
>
> +
>
> Please send any updated version cc'ing Rafael, who kindly offered to 
> pick up this patch
>
>>
[...]
>> @@ -503,13 +503,13 @@ static int hisi_lpc_acpi_probe(struct device 
>> *hostdev)
>>   {
>>       struct acpi_device *adev = ACPI_COMPANION(hostdev);
>>       struct acpi_device *child;
>> +    struct platform_device *pdev;
>
> nit: please maintain reverse-firtree ordering
OK
>
>>       int ret;
>>         /* Only consider the children of the host */
>>       list_for_each_entry(child, &adev->children, node) {
>>           const char *hid = acpi_device_hid(child);
>>           const struct hisi_lpc_acpi_cell *cell;
>> -        struct platform_device *pdev;
>>           const struct resource *res;
>>           bool found = false;
>>           int num_res;
>> @@ -571,22 +571,24 @@ static int hisi_lpc_acpi_probe(struct device 
>> *hostdev)
>>             ret = platform_device_add_resources(pdev, res, num_res);
>>           if (ret)
>> -            goto fail;
>> +            goto fail_put_device;
>>             ret = platform_device_add_data(pdev, cell->pdata,
>>                              cell->pdata_size);
>>           if (ret)
>> -            goto fail;
>> +            goto fail_put_device;
>>             ret = platform_device_add(pdev);
>>           if (ret)
>> -            goto fail;
>> +            goto fail_put_device;
>>             acpi_device_set_enumerated(child);
>>       }
>>         return 0;
>>   +fail_put_device:
>> +    platform_device_put(pdev);
>
> is this enough? As I see, this invokes platform_device_release(), but 
> we would still need platform_device_del() to drop the pdev resources. 
> hisi_lpc_acpi_remove_subdev() calls platform_device_unregister(), so 
> it seems proper to do that here also. Please check it.
The resource allocated in platform_device_add_resources() is inserted by 
platform_device_add(), if platform_device_add() is not called 
successfully, freeing the resource in platform_device_release() is enough.
>
> Thanks,
> John
>
>>   fail:
>>       hisi_lpc_acpi_remove(hostdev);
>>       return ret;
>
> .

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

end of thread, other threads:[~2022-07-04  9:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-01  9:43 [PATCH] bus: hisi_lpc: fix missing platform_device_put() in hisi_lpc_acpi_probe() Yang Yingliang
2022-07-04  8:01 ` John Garry
2022-07-04  9:11   ` Yang Yingliang

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.