diff mbox series

[v2] coresight: syscfg: Fix memleak on registration failure in cscfg_create_device

Message ID 20220124124121.8888-1-linmq006@gmail.com (mailing list archive)
State New, archived
Headers show
Series [v2] coresight: syscfg: Fix memleak on registration failure in cscfg_create_device | expand

Commit Message

Miaoqian Lin Jan. 24, 2022, 12:41 p.m. UTC
device_register() calls device_initialize(),
according to doc of device_initialize:

    Use put_device() to give up your reference instead of freeing
    * @dev directly once you have called this function.

To prevent potential memleak, use put_device() for error handling.

Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
Changes in v2:
- simply call put_device() instead of cscfg_dev_release() in the error
path of cscfg_create_device.
---
 drivers/hwtracing/coresight/coresight-syscfg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Mathieu Poirier Feb. 1, 2022, 5:13 p.m. UTC | #1
On Mon, Jan 24, 2022 at 12:41:21PM +0000, Miaoqian Lin wrote:
> device_register() calls device_initialize(),
> according to doc of device_initialize:
> 
>     Use put_device() to give up your reference instead of freeing
>     * @dev directly once you have called this function.
> 
> To prevent potential memleak, use put_device() for error handling.
> 
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
> Changes in v2:
> - simply call put_device() instead of cscfg_dev_release() in the error
> path of cscfg_create_device.
> ---
>  drivers/hwtracing/coresight/coresight-syscfg.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c
> index 43054568430f..c30989e0675f 100644
> --- a/drivers/hwtracing/coresight/coresight-syscfg.c
> +++ b/drivers/hwtracing/coresight/coresight-syscfg.c
> @@ -791,7 +791,7 @@ static int cscfg_create_device(void)
>  
>  	err = device_register(dev);
>  	if (err)
> -		cscfg_dev_release(dev);
> +		put_device(dev);

Applied.

Thanks,
Mathieu

>  
>  create_dev_exit_unlock:
>  	mutex_unlock(&cscfg_mutex);
> -- 
> 2.17.1
>
diff mbox series

Patch

diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c
index 43054568430f..c30989e0675f 100644
--- a/drivers/hwtracing/coresight/coresight-syscfg.c
+++ b/drivers/hwtracing/coresight/coresight-syscfg.c
@@ -791,7 +791,7 @@  static int cscfg_create_device(void)
 
 	err = device_register(dev);
 	if (err)
-		cscfg_dev_release(dev);
+		put_device(dev);
 
 create_dev_exit_unlock:
 	mutex_unlock(&cscfg_mutex);