meson: i2c: fix coverity warning
authorYingyuan Zhu <yingyuan.zhu@amlogic.com>
Wed, 29 Aug 2018 02:49:05 +0000 (10:49 +0800)
committerJianxin Pan <jianxin.pan@amlogic.com>
Thu, 6 Sep 2018 13:55:55 +0000 (06:55 -0700)
PD#172722: meson: i2c: fix coverity warning

When the function "devm_ioremap_resource" returns
an error,the previously applied memory resource
"slave" is not released.
This causes resource leak.

Change-Id: I2dfb7fab007977e1ae57e714ae489fbf80ec7103
Signed-off-by: Yingyuan Zhu <yingyuan.zhu@amlogic.com>
drivers/amlogic/i2c/aml_slave.c

index e6cd323e16dd23895a36a3f01b970bbfe5a6bee8..a82966ba7128c1cc9b0d56d5ac39fee709e82406 100644 (file)
@@ -182,7 +182,8 @@ static int i2c_slave_probe(struct platform_device *pdev)
        if (!strcmp(i2c_auto_test_mode, "open"))
                i2c_auto_test_flag = 1;
 
-       slave = kzalloc(sizeof(struct aml_i2c_slave), GFP_KERNEL);
+       slave = devm_kzalloc(&pdev->dev, sizeof(struct aml_i2c_slave),
+               GFP_KERNEL);
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 
@@ -246,7 +247,6 @@ static int i2c_slave_remove(struct platform_device *pdev)
        class_destroy(&slave->cls);
        mutex_destroy(slave->lock);
        free_irq(slave->irq, slave);
-       kzfree(slave);
        return 0;
 }
 static int i2c_slave_suspend(struct device *dev)