hwmon: (ltc4261) Convert to use devm_kzalloc
authorGuenter Roeck <linux@roeck-us.net>
Wed, 22 Feb 2012 16:56:49 +0000 (08:56 -0800)
committerGuenter Roeck <guenter.roeck@ericsson.com>
Mon, 19 Mar 2012 01:27:46 +0000 (18:27 -0700)
Marginally less code and eliminate the possibility of memory leaks.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/ltc4261.c

index ab1bfbf2a3f0081c766097a2b73a0bc775506e3d..069b7d34d8f9216252678a056efcf5203c02e114 100644 (file)
@@ -235,11 +235,9 @@ static int ltc4261_probe(struct i2c_client *client,
                return -ENODEV;
        }
 
-       data = kzalloc(sizeof(*data), GFP_KERNEL);
-       if (!data) {
-               ret = -ENOMEM;
-               goto out_kzalloc;
-       }
+       data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
+       if (!data)
+               return -ENOMEM;
 
        i2c_set_clientdata(client, data);
        mutex_init(&data->update_lock);
@@ -250,7 +248,7 @@ static int ltc4261_probe(struct i2c_client *client,
        /* Register sysfs hooks */
        ret = sysfs_create_group(&client->dev.kobj, &ltc4261_group);
        if (ret)
-               goto out_sysfs_create_group;
+               return ret;
 
        data->hwmon_dev = hwmon_device_register(&client->dev);
        if (IS_ERR(data->hwmon_dev)) {
@@ -262,9 +260,6 @@ static int ltc4261_probe(struct i2c_client *client,
 
 out_hwmon_device_register:
        sysfs_remove_group(&client->dev.kobj, &ltc4261_group);
-out_sysfs_create_group:
-       kfree(data);
-out_kzalloc:
        return ret;
 }
 
@@ -275,8 +270,6 @@ static int ltc4261_remove(struct i2c_client *client)
        hwmon_device_unregister(data->hwmon_dev);
        sysfs_remove_group(&client->dev.kobj, &ltc4261_group);
 
-       kfree(data);
-
        return 0;
 }