[media] marvell-ccic: fix memory leak on failure path in cafe_smbus_setup()
authorAlexey Khoroshilov <khoroshilov@ispras.ru>
Sat, 4 Apr 2015 00:16:01 +0000 (21:16 -0300)
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>
Fri, 1 May 2015 10:50:54 +0000 (07:50 -0300)
If i2c_add_adapter() fails, adap is not deallocated.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Acked-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
drivers/media/platform/marvell-ccic/cafe-driver.c

index e857405b46fdf4871494e5cb4cc01de1c84028b9..77890bd0deab75d9aa85852bb68f9aef20124303 100644 (file)
@@ -339,17 +339,21 @@ static int cafe_smbus_setup(struct cafe_camera *cam)
        adap = kzalloc(sizeof(*adap), GFP_KERNEL);
        if (adap == NULL)
                return -ENOMEM;
-       cam->mcam.i2c_adapter = adap;
-       cafe_smbus_enable_irq(cam);
        adap->owner = THIS_MODULE;
        adap->algo = &cafe_smbus_algo;
        strcpy(adap->name, "cafe_ccic");
        adap->dev.parent = &cam->pdev->dev;
        i2c_set_adapdata(adap, cam);
        ret = i2c_add_adapter(adap);
-       if (ret)
+       if (ret) {
                printk(KERN_ERR "Unable to register cafe i2c adapter\n");
-       return ret;
+               kfree(adap);
+               return ret;
+       }
+
+       cam->mcam.i2c_adapter = adap;
+       cafe_smbus_enable_irq(cam);
+       return 0;
 }
 
 static void cafe_smbus_shutdown(struct cafe_camera *cam)