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

Navid Emamdoost navid.emamdoost at gmail.com
Sun Oct 27 17:32:33 UTC 2019


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 at gmail.com>
---
 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);
-	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)
-- 
2.17.1



More information about the dri-devel mailing list