Re: [PATCH RESEND] fpga: region: Fix possible memory leak in fpga_region_register_full()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Sep 28, 2023 at 05:16:36PM +0800, Jinjie Ruan wrote:
> If device_register() fails in fpga_region_register_full(), the region
> allocated by kzalloc() and the id allocated by ida_alloc() also need be
> freed otherwise will cause memory leak.

How did you observe the memory leak? Please help provide some trace.

Thanks,
Yilun

> 
> Fixes: 8886a579744f ("fpga: region: Use standard dev_release for class driver")
> Signed-off-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx>
> ---
>  drivers/fpga/fpga-region.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/fpga/fpga-region.c b/drivers/fpga/fpga-region.c
> index b364a929425c..9dc6314976ef 100644
> --- a/drivers/fpga/fpga-region.c
> +++ b/drivers/fpga/fpga-region.c
> @@ -228,12 +228,13 @@ fpga_region_register_full(struct device *parent, const struct fpga_region_info *
>  
>  	ret = device_register(&region->dev);
>  	if (ret) {
> -		put_device(&region->dev);
> -		return ERR_PTR(ret);
> +		goto err_put_device;
>  	}
>  
>  	return region;
>  
> +err_put_device:
> +	put_device(&region->dev);
>  err_remove:
>  	ida_free(&fpga_region_ida, id);
>  err_free:
> -- 
> 2.34.1
> 



[Index of Archives]     [LM Sensors]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux