diff mbox series

[v2,1/4] staging: vc04_services: Stop leaking platform device on error path

Message ID 20221222191500.515795-2-umang.jain@ideasonboard.com (mailing list archive)
State New, archived
Headers show
Series staging: vchiq: Rework child platform device (un)register | expand

Commit Message

Umang Jain Dec. 22, 2022, 7:14 p.m. UTC
vchiq driver registers the child platform devices in
vchiq_register_child(). However, in the registration error code path,
currently the driver is leaking platform devices by not destroying the
return platform device. Plug this leak using platform_device_put() as
mentioned in the documentation for platform_device_register().

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
---
 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Stefan Wahren Dec. 22, 2022, 7:23 p.m. UTC | #1
Hi Umang,

Am 22.12.22 um 20:14 schrieb Umang Jain:
> vchiq driver registers the child platform devices in
> vchiq_register_child(). However, in the registration error code path,
> currently the driver is leaking platform devices by not destroying the
> return platform device. Plug this leak using platform_device_put() as
> mentioned in the documentation for platform_device_register().
>
> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
> ---
>   drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> index dc33490ba7fb..fc7ea7ba97b2 100644
> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> @@ -1779,6 +1779,7 @@ vchiq_register_child(struct platform_device *pdev, const char *name)
>   	child = platform_device_register_full(&pdevinfo);
>   	if (IS_ERR(child)) {
>   		dev_warn(&pdev->dev, "%s not registered\n", name);
> +		platform_device_put(child);
why should we free an error?
>   		child = NULL;
>   	}
>
Laurent Pinchart Dec. 22, 2022, 8:30 p.m. UTC | #2
Hi Umang,

Thank you for the patch.

On Fri, Dec 23, 2022 at 12:44:57AM +0530, Umang Jain wrote:
> vchiq driver registers the child platform devices in
> vchiq_register_child(). However, in the registration error code path,
> currently the driver is leaking platform devices by not destroying the
> return platform device. Plug this leak using platform_device_put() as
> mentioned in the documentation for platform_device_register().
> 
> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
> ---
>  drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> index dc33490ba7fb..fc7ea7ba97b2 100644
> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> @@ -1779,6 +1779,7 @@ vchiq_register_child(struct platform_device *pdev, const char *name)
>  	child = platform_device_register_full(&pdevinfo);
>  	if (IS_ERR(child)) {
>  		dev_warn(&pdev->dev, "%s not registered\n", name);
> +		platform_device_put(child);

If IS_ERR(child), what do you expect platform_device_put(child) to do ?
And have you read the implementation of platform_device_register_full()
?

>  		child = NULL;
>  	}
>
Umang Jain Dec. 23, 2022, 5:28 a.m. UTC | #3
Hi,

On 12/23/22 2:00 AM, Laurent Pinchart wrote:
> Hi Umang,
>
> Thank you for the patch.
>
> On Fri, Dec 23, 2022 at 12:44:57AM +0530, Umang Jain wrote:
>> vchiq driver registers the child platform devices in
>> vchiq_register_child(). However, in the registration error code path,
>> currently the driver is leaking platform devices by not destroying the
>> return platform device. Plug this leak using platform_device_put() as
>> mentioned in the documentation for platform_device_register().
>>
>> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
>> ---
>>   drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
>> index dc33490ba7fb..fc7ea7ba97b2 100644
>> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
>> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
>> @@ -1779,6 +1779,7 @@ vchiq_register_child(struct platform_device *pdev, const char *name)
>>   	child = platform_device_register_full(&pdevinfo);
>>   	if (IS_ERR(child)) {
>>   		dev_warn(&pdev->dev, "%s not registered\n", name);
>> +		platform_device_put(child);
> If IS_ERR(child), what do you expect platform_device_put(child) to do ?
> And have you read the implementation of platform_device_register_full()
> ?

Errr, yeah - it is handling the platform_device_put() as well. Stupid me!

(dropping this patch for v3)
>
>>   		child = NULL;
>>   	}
>>
diff mbox series

Patch

diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index dc33490ba7fb..fc7ea7ba97b2 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -1779,6 +1779,7 @@  vchiq_register_child(struct platform_device *pdev, const char *name)
 	child = platform_device_register_full(&pdevinfo);
 	if (IS_ERR(child)) {
 		dev_warn(&pdev->dev, "%s not registered\n", name);
+		platform_device_put(child);
 		child = NULL;
 	}