MLK-20404: sensor: fix potential memory leaks for ov5640
authorGuoniu.Zhou <guoniu.zhou@nxp.com>
Mon, 19 Nov 2018 07:14:05 +0000 (15:14 +0800)
committerLeonard Crestez <leonard.crestez@nxp.com>
Wed, 17 Apr 2019 23:51:34 +0000 (02:51 +0300)
Driver does not free memory when it's removed or encounter
an error in probe. So fix potential memory leaks.

Signed-off-by: Guoniu.Zhou <guoniu.zhou@nxp.com>
drivers/media/platform/imx8/ov5640_mipi_v3.c

index 02a3db4..e1197e7 100644 (file)
@@ -1201,7 +1201,9 @@ static int ov5640_probe(struct i2c_client *client,
        u8 chip_id_high, chip_id_low;
        struct ov5640 *sensor;
 
-       sensor = kmalloc(sizeof(*sensor), GFP_KERNEL);
+       sensor = devm_kmalloc(dev, sizeof(*sensor), GFP_KERNEL);
+       if (!sensor)
+               return -ENOMEM;
        /* Set initial values for the sensor struct. */
        memset(sensor, 0, sizeof(*sensor));