video: fbdev: lcd_mipid: Fix a memory leak in an error handling path

Message ID 8b82e34724755b69f34f15dddb288cd373080390.1620505229.git.christophe.jaillet@wanadoo.fr
State New
Headers show
Series
  • video: fbdev: lcd_mipid: Fix a memory leak in an error handling path
Related show

Commit Message

Christophe JAILLET May 8, 2021, 8:23 p.m.
If 'mipid_detect()' fails, we must free 'md' to avoid a memory leak.

While at it, modernize the function:
   - remove a useless message in case of memory allocation failure
   - change a '== NULL' into a '!'

Fixes: 66d2f99d0bb5 ("omapfb: add support for MIPI-DCS compatible LCDs")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/video/fbdev/omap/lcd_mipid.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Patch

diff --git a/drivers/video/fbdev/omap/lcd_mipid.c b/drivers/video/fbdev/omap/lcd_mipid.c
index a75ae0c9b14c..b4b93ff4b41a 100644
--- a/drivers/video/fbdev/omap/lcd_mipid.c
+++ b/drivers/video/fbdev/omap/lcd_mipid.c
@@ -551,10 +551,8 @@  static int mipid_spi_probe(struct spi_device *spi)
 	int r;
 
 	md = kzalloc(sizeof(*md), GFP_KERNEL);
-	if (md == NULL) {
-		dev_err(&spi->dev, "out of memory\n");
+	if (!md)
 		return -ENOMEM;
-	}
 
 	spi->mode = SPI_MODE_0;
 	md->spi = spi;
@@ -563,11 +561,15 @@  static int mipid_spi_probe(struct spi_device *spi)
 
 	r = mipid_detect(md);
 	if (r < 0)
-		return r;
+		goto free_md;
 
 	omapfb_register_panel(&md->panel);
 
 	return 0;
+
+free_md:
+	kfree(md);
+	return r;
 }
 
 static int mipid_spi_remove(struct spi_device *spi)