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@xxxxxxxxxx> --- drivers/video/fbdev/omap/lcd_mipid.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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) -- 2.30.2