misc: bh1780: Introduce the use of devm_kzalloc

This patch introduces the use of devm_kzalloc and does away with the
kfrees in the probe and remove functions. A label and the kfree
being called on the return path of failure on i2c_check_functionality,
which is completely unnecessary and removed. The NULL assignment of
ddata is no longer required is also done away with.

Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Himangi Saraogi 2014-07-24 02:45:40 +05:30 committed by Greg Kroah-Hartman
parent ee5311420d
commit 7b9d1f0b7a

View File

@ -149,50 +149,35 @@ static int bh1780_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
int ret; int ret;
struct bh1780_data *ddata = NULL; struct bh1780_data *ddata;
struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) { if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE))
ret = -EIO; return -EIO;
goto err_op_failed;
}
ddata = kzalloc(sizeof(struct bh1780_data), GFP_KERNEL); ddata = devm_kzalloc(&client->dev, sizeof(struct bh1780_data),
if (ddata == NULL) { GFP_KERNEL);
ret = -ENOMEM; if (ddata == NULL)
goto err_op_failed; return -ENOMEM;
}
ddata->client = client; ddata->client = client;
i2c_set_clientdata(client, ddata); i2c_set_clientdata(client, ddata);
ret = bh1780_read(ddata, BH1780_REG_PARTID, "PART ID"); ret = bh1780_read(ddata, BH1780_REG_PARTID, "PART ID");
if (ret < 0) if (ret < 0)
goto err_op_failed; return ret;
dev_info(&client->dev, "Ambient Light Sensor, Rev : %d\n", dev_info(&client->dev, "Ambient Light Sensor, Rev : %d\n",
(ret & BH1780_REVMASK)); (ret & BH1780_REVMASK));
mutex_init(&ddata->lock); mutex_init(&ddata->lock);
ret = sysfs_create_group(&client->dev.kobj, &bh1780_attr_group); return sysfs_create_group(&client->dev.kobj, &bh1780_attr_group);
if (ret)
goto err_op_failed;
return 0;
err_op_failed:
kfree(ddata);
return ret;
} }
static int bh1780_remove(struct i2c_client *client) static int bh1780_remove(struct i2c_client *client)
{ {
struct bh1780_data *ddata;
ddata = i2c_get_clientdata(client);
sysfs_remove_group(&client->dev.kobj, &bh1780_attr_group); sysfs_remove_group(&client->dev.kobj, &bh1780_attr_group);
kfree(ddata);
return 0; return 0;
} }