drivers/misc: at24: convert to use devm_kzalloc

Use devm_kzalloc to make cleanup paths simpler

Signed-off-by: Nikolay Balandin <nbalandin@dev.rtsoft.ru>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Nikolay Balandin 2013-05-28 13:00:20 -07:00 committed by Greg Kroah-Hartman
parent 84524cf43d
commit f0ac23639c
1 changed files with 15 additions and 29 deletions

View File

@ -492,10 +492,9 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
if (client->dev.platform_data) { if (client->dev.platform_data) {
chip = *(struct at24_platform_data *)client->dev.platform_data; chip = *(struct at24_platform_data *)client->dev.platform_data;
} else { } else {
if (!id->driver_data) { if (!id->driver_data)
err = -ENODEV; return -ENODEV;
goto err_out;
}
magic = id->driver_data; magic = id->driver_data;
chip.byte_len = BIT(magic & AT24_BITMASK(AT24_SIZE_BYTELEN)); chip.byte_len = BIT(magic & AT24_BITMASK(AT24_SIZE_BYTELEN));
magic >>= AT24_SIZE_BYTELEN; magic >>= AT24_SIZE_BYTELEN;
@ -519,8 +518,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
"byte_len looks suspicious (no power of 2)!\n"); "byte_len looks suspicious (no power of 2)!\n");
if (!chip.page_size) { if (!chip.page_size) {
dev_err(&client->dev, "page_size must not be 0!\n"); dev_err(&client->dev, "page_size must not be 0!\n");
err = -EINVAL; return -EINVAL;
goto err_out;
} }
if (!is_power_of_2(chip.page_size)) if (!is_power_of_2(chip.page_size))
dev_warn(&client->dev, dev_warn(&client->dev,
@ -528,10 +526,9 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
/* Use I2C operations unless we're stuck with SMBus extensions. */ /* Use I2C operations unless we're stuck with SMBus extensions. */
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
if (chip.flags & AT24_FLAG_ADDR16) { if (chip.flags & AT24_FLAG_ADDR16)
err = -EPFNOSUPPORT; return -EPFNOSUPPORT;
goto err_out;
}
if (i2c_check_functionality(client->adapter, if (i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
use_smbus = I2C_SMBUS_I2C_BLOCK_DATA; use_smbus = I2C_SMBUS_I2C_BLOCK_DATA;
@ -542,8 +539,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
I2C_FUNC_SMBUS_READ_BYTE_DATA)) { I2C_FUNC_SMBUS_READ_BYTE_DATA)) {
use_smbus = I2C_SMBUS_BYTE_DATA; use_smbus = I2C_SMBUS_BYTE_DATA;
} else { } else {
err = -EPFNOSUPPORT; return -EPFNOSUPPORT;
goto err_out;
} }
} }
@ -553,12 +549,10 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
num_addresses = DIV_ROUND_UP(chip.byte_len, num_addresses = DIV_ROUND_UP(chip.byte_len,
(chip.flags & AT24_FLAG_ADDR16) ? 65536 : 256); (chip.flags & AT24_FLAG_ADDR16) ? 65536 : 256);
at24 = kzalloc(sizeof(struct at24_data) + at24 = devm_kzalloc(&client->dev, sizeof(struct at24_data) +
num_addresses * sizeof(struct i2c_client *), GFP_KERNEL); num_addresses * sizeof(struct i2c_client *), GFP_KERNEL);
if (!at24) { if (!at24)
err = -ENOMEM; return -ENOMEM;
goto err_out;
}
mutex_init(&at24->lock); mutex_init(&at24->lock);
at24->use_smbus = use_smbus; at24->use_smbus = use_smbus;
@ -596,11 +590,10 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
at24->write_max = write_max; at24->write_max = write_max;
/* buffer (data + address at the beginning) */ /* buffer (data + address at the beginning) */
at24->writebuf = kmalloc(write_max + 2, GFP_KERNEL); at24->writebuf = devm_kzalloc(&client->dev,
if (!at24->writebuf) { write_max + 2, GFP_KERNEL);
err = -ENOMEM; if (!at24->writebuf)
goto err_struct; return -ENOMEM;
}
} else { } else {
dev_warn(&client->dev, dev_warn(&client->dev,
"cannot write due to controller restrictions."); "cannot write due to controller restrictions.");
@ -648,11 +641,6 @@ err_clients:
if (at24->client[i]) if (at24->client[i])
i2c_unregister_device(at24->client[i]); i2c_unregister_device(at24->client[i]);
kfree(at24->writebuf);
err_struct:
kfree(at24);
err_out:
dev_dbg(&client->dev, "probe error %d\n", err);
return err; return err;
} }
@ -667,8 +655,6 @@ static int at24_remove(struct i2c_client *client)
for (i = 1; i < at24->num_addresses; i++) for (i = 1; i < at24->num_addresses; i++)
i2c_unregister_device(at24->client[i]); i2c_unregister_device(at24->client[i]);
kfree(at24->writebuf);
kfree(at24);
return 0; return 0;
} }