Re: [PATCH v2 1/3] ARM: locomo: use put_device() on device_register() failure

Sourabh Jain <[email protected]>
Newsgroups gmane.linux.ports.ppc.embedded
Message-ID <014a7724-4955-4fb5-b331-ab5fc9abf806__44342.1360266925$1786691358$gmane$org@linux.ibm.com>

On 13/08/26 15:24, Tarun Sahu wrote:
> When device_register() fails, calling kfree(dev) directly bypasses the
> device_release() callback (locomo_dev_release) and leaks internal driver
> core structures allocated during device initialization.
>
> Fix this by replacing direct kfree(dev) with put_device(&dev->dev) when
> device_register() returns an error, ensuring proper refcount decrement
> and cleanup via locomo_dev_release().
>
> Signed-off-by: Tarun Sahu <[email protected]>
> ---
>   arch/arm/common/locomo.c | 13 ++++++-------
>   1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/arch/arm/common/locomo.c b/arch/arm/common/locomo.c
> index 55e360452828..0f6689d343b0 100644
> --- a/arch/arm/common/locomo.c
> +++ b/arch/arm/common/locomo.c
> @@ -223,10 +223,8 @@ locomo_init_one_child(struct locomo *lchip, struct locomo_dev_info *info)
>   	int ret;
>   
>   	dev = kzalloc_obj(struct locomo_dev);
> -	if (!dev) {
> -		ret = -ENOMEM;
> -		goto out;
> -	}
> +	if (!dev)
> +		return -ENOMEM;
>   
>   	/*
>   	 * If the parent device has a DMA mask associated with it,
> @@ -255,10 +253,11 @@ locomo_init_one_child(struct locomo *lchip, struct locomo_dev_info *info)
>   
>   	ret = device_register(&dev->dev);
>   	if (ret) {
> - out:
> -		kfree(dev);
> +		put_device(&dev->dev);
> +		return ret;
>   	}
> -	return ret;
> +
> +	return 0;
>   }

Changes look good to me. Feel free to add:
Reviewed-by: Sourabh Jain <[email protected]>

>   
>   #ifdef CONFIG_PM
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.