Re: [PATCH] drm/tinydrm: Fix memroy leak in hx8357d_probe

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

 



Hi Navid,

Den 27.10.2019 18.32, skrev Navid Emamdoost:
> In the implementation of hx8357d_probe() the allocated memory for dbidev
> is leaked when an error happens. Release dbidev if any of the  following
> calls fail: devm_gpiod_get(), devm_of_find_backlight(),
> mipi_dbi_spi_init(), mipi_dbi_init(), drm_dev_register().
> 
> Fixes: f300c86e33a6 ("drm: Add an hx8367d tinydrm driver.")
> Signed-off-by: Navid Emamdoost <navid.emamdoost@xxxxxxxxx>
> ---
>  drivers/gpu/drm/tiny/hx8357d.c | 25 +++++++++++++++----------
>  1 file changed, 15 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/gpu/drm/tiny/hx8357d.c b/drivers/gpu/drm/tiny/hx8357d.c
> index 9af8ff84974f..da5ec944f47e 100644
> --- a/drivers/gpu/drm/tiny/hx8357d.c
> +++ b/drivers/gpu/drm/tiny/hx8357d.c
> @@ -232,44 +232,49 @@ static int hx8357d_probe(struct spi_device *spi)
>  
>  	drm = &dbidev->drm;
>  	ret = devm_drm_dev_init(dev, drm, &hx8357d_driver);

This is a device managed function that releases its resource(s) on
device:driver unbind like the other devm_ functions (it can't free
dbidev if it fails hence the kfree in the error path here).

This is the release call path:

devm_drm_dev_init_release -> drm_dev_put -> drm_dev_release ->
dev->driver->release : mipi_dbi_release.

Noralf.

> -	if (ret) {
> -		kfree(dbidev);
> -		return ret;
> -	}
> +	if (ret)
> +		goto free_dbidev;
>  
>  	drm_mode_config_init(drm);
>  
>  	dc = devm_gpiod_get(dev, "dc", GPIOD_OUT_LOW);
>  	if (IS_ERR(dc)) {
>  		DRM_DEV_ERROR(dev, "Failed to get gpio 'dc'\n");
> -		return PTR_ERR(dc);
> +		ret = PTR_ERR(dc);
> +		goto free_dbidev;
>  	}
>  
>  	dbidev->backlight = devm_of_find_backlight(dev);
> -	if (IS_ERR(dbidev->backlight))
> -		return PTR_ERR(dbidev->backlight);
> +	if (IS_ERR(dbidev->backlight)) {
> +		ret = PTR_ERR(dbidev->backlight);
> +		goto free_dbidev;
> +	}
>  
>  	device_property_read_u32(dev, "rotation", &rotation);
>  
>  	ret = mipi_dbi_spi_init(spi, &dbidev->dbi, dc);
>  	if (ret)
> -		return ret;
> +		goto free_dbidev;
>  
>  	ret = mipi_dbi_dev_init(dbidev, &hx8357d_pipe_funcs, &yx350hv15_mode, rotation);
>  	if (ret)
> -		return ret;
> +		goto free_dbidev;
>  
>  	drm_mode_config_reset(drm);
>  
>  	ret = drm_dev_register(drm, 0);
>  	if (ret)
> -		return ret;
> +		goto free_dbidev;
>  
>  	spi_set_drvdata(spi, drm);
>  
>  	drm_fbdev_generic_setup(drm, 0);
>  
>  	return 0;
> +
> +free_dbidev:
> +	kfree(dbidev);
> +	return ret;
>  }
>  
>  static int hx8357d_remove(struct spi_device *spi)
> 
_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux