input: misc: compass: akm89xx: fix memory leak and race on accessing inf
David Yu [Tue, 23 Apr 2013 06:41:08 +0000 (15:41 +0900)]
Bug 1276763

Change-Id: Ia16541ac45642c4758b55f041a6c3bc89dc6a00f
Signed-off-by: David Yu <davyu@nvidia.com>
(cherry picked from commit 8933e396c73d6ad7d8c1621649ef57fd6d32f534)
Reviewed-on: http://git-master/r/243008
Reviewed-by: Seema Khowala <seemaj@nvidia.com>
Tested-by: Seema Khowala <seemaj@nvidia.com>

drivers/input/misc/compass/ak8975_input.c

index 841f975..cfa6115 100644 (file)
@@ -1113,7 +1113,6 @@ static int akm_remove(struct i2c_client *client)
                akm_pm_exit(inf);
                if (&inf->mutex_data)
                        mutex_destroy(&inf->mutex_data);
-               kfree(inf);
        }
        dev_info(&client->dev, "%s\n", __func__);
        return 0;
@@ -1173,7 +1172,7 @@ static int akm_probe(struct i2c_client *client,
        int err;
 
        dev_info(&client->dev, "%s\n", __func__);
-       inf = kzalloc(sizeof(*inf), GFP_KERNEL);
+       inf = devm_kzalloc(&client->dev, sizeof(*inf), GFP_KERNEL);
        if (!inf) {
                dev_err(&client->dev, "%s kzalloc ERR\n", __func__);
                return -ENOMEM;
@@ -1187,10 +1186,8 @@ static int akm_probe(struct i2c_client *client,
        else
                pd = (struct mpu_platform_data *)dev_get_platdata(&client->dev);
 
-       if (!pd || IS_ERR(pd)) {
-               kfree(inf);
+       if (!pd || IS_ERR(pd))
                return -EINVAL;
-       }
 
        inf->pdata = *pd;