diff options
author | Nikolay Balandin <nbalandin@dev.rtsoft.ru> | 2013-05-28 16:00:20 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-05-30 08:49:32 -0400 |
commit | f0ac23639c62add367309101d18ae2aa1d4a377c (patch) | |
tree | a69f88bb9eb281c3944da73b821ca7f9e8e7d0b5 /drivers/misc | |
parent | 84524cf43d693746896782628466205ccc193e0d (diff) |
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>
Diffstat (limited to 'drivers/misc')
-rw-r--r-- | drivers/misc/eeprom/at24.c | 44 |
1 files changed, 15 insertions, 29 deletions
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 2baeec56edfe..5d4fd69d04ca 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c | |||
@@ -492,10 +492,9 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
492 | if (client->dev.platform_data) { | 492 | if (client->dev.platform_data) { |
493 | chip = *(struct at24_platform_data *)client->dev.platform_data; | 493 | chip = *(struct at24_platform_data *)client->dev.platform_data; |
494 | } else { | 494 | } else { |
495 | if (!id->driver_data) { | 495 | if (!id->driver_data) |
496 | err = -ENODEV; | 496 | return -ENODEV; |
497 | goto err_out; | 497 | |
498 | } | ||
499 | magic = id->driver_data; | 498 | magic = id->driver_data; |
500 | chip.byte_len = BIT(magic & AT24_BITMASK(AT24_SIZE_BYTELEN)); | 499 | chip.byte_len = BIT(magic & AT24_BITMASK(AT24_SIZE_BYTELEN)); |
501 | magic >>= AT24_SIZE_BYTELEN; | 500 | magic >>= AT24_SIZE_BYTELEN; |
@@ -519,8 +518,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
519 | "byte_len looks suspicious (no power of 2)!\n"); | 518 | "byte_len looks suspicious (no power of 2)!\n"); |
520 | if (!chip.page_size) { | 519 | if (!chip.page_size) { |
521 | dev_err(&client->dev, "page_size must not be 0!\n"); | 520 | dev_err(&client->dev, "page_size must not be 0!\n"); |
522 | err = -EINVAL; | 521 | return -EINVAL; |
523 | goto err_out; | ||
524 | } | 522 | } |
525 | if (!is_power_of_2(chip.page_size)) | 523 | if (!is_power_of_2(chip.page_size)) |
526 | dev_warn(&client->dev, | 524 | dev_warn(&client->dev, |
@@ -528,10 +526,9 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
528 | 526 | ||
529 | /* Use I2C operations unless we're stuck with SMBus extensions. */ | 527 | /* Use I2C operations unless we're stuck with SMBus extensions. */ |
530 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { | 528 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { |
531 | if (chip.flags & AT24_FLAG_ADDR16) { | 529 | if (chip.flags & AT24_FLAG_ADDR16) |
532 | err = -EPFNOSUPPORT; | 530 | return -EPFNOSUPPORT; |
533 | goto err_out; | 531 | |
534 | } | ||
535 | if (i2c_check_functionality(client->adapter, | 532 | if (i2c_check_functionality(client->adapter, |
536 | I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { | 533 | I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { |
537 | use_smbus = I2C_SMBUS_I2C_BLOCK_DATA; | 534 | 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) | |||
542 | I2C_FUNC_SMBUS_READ_BYTE_DATA)) { | 539 | I2C_FUNC_SMBUS_READ_BYTE_DATA)) { |
543 | use_smbus = I2C_SMBUS_BYTE_DATA; | 540 | use_smbus = I2C_SMBUS_BYTE_DATA; |
544 | } else { | 541 | } else { |
545 | err = -EPFNOSUPPORT; | 542 | return -EPFNOSUPPORT; |
546 | goto err_out; | ||
547 | } | 543 | } |
548 | } | 544 | } |
549 | 545 | ||
@@ -553,12 +549,10 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
553 | num_addresses = DIV_ROUND_UP(chip.byte_len, | 549 | num_addresses = DIV_ROUND_UP(chip.byte_len, |
554 | (chip.flags & AT24_FLAG_ADDR16) ? 65536 : 256); | 550 | (chip.flags & AT24_FLAG_ADDR16) ? 65536 : 256); |
555 | 551 | ||
556 | at24 = kzalloc(sizeof(struct at24_data) + | 552 | at24 = devm_kzalloc(&client->dev, sizeof(struct at24_data) + |
557 | num_addresses * sizeof(struct i2c_client *), GFP_KERNEL); | 553 | num_addresses * sizeof(struct i2c_client *), GFP_KERNEL); |
558 | if (!at24) { | 554 | if (!at24) |
559 | err = -ENOMEM; | 555 | return -ENOMEM; |
560 | goto err_out; | ||
561 | } | ||
562 | 556 | ||
563 | mutex_init(&at24->lock); | 557 | mutex_init(&at24->lock); |
564 | at24->use_smbus = use_smbus; | 558 | at24->use_smbus = use_smbus; |
@@ -596,11 +590,10 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
596 | at24->write_max = write_max; | 590 | at24->write_max = write_max; |
597 | 591 | ||
598 | /* buffer (data + address at the beginning) */ | 592 | /* buffer (data + address at the beginning) */ |
599 | at24->writebuf = kmalloc(write_max + 2, GFP_KERNEL); | 593 | at24->writebuf = devm_kzalloc(&client->dev, |
600 | if (!at24->writebuf) { | 594 | write_max + 2, GFP_KERNEL); |
601 | err = -ENOMEM; | 595 | if (!at24->writebuf) |
602 | goto err_struct; | 596 | return -ENOMEM; |
603 | } | ||
604 | } else { | 597 | } else { |
605 | dev_warn(&client->dev, | 598 | dev_warn(&client->dev, |
606 | "cannot write due to controller restrictions."); | 599 | "cannot write due to controller restrictions."); |
@@ -648,11 +641,6 @@ err_clients: | |||
648 | if (at24->client[i]) | 641 | if (at24->client[i]) |
649 | i2c_unregister_device(at24->client[i]); | 642 | i2c_unregister_device(at24->client[i]); |
650 | 643 | ||
651 | kfree(at24->writebuf); | ||
652 | err_struct: | ||
653 | kfree(at24); | ||
654 | err_out: | ||
655 | dev_dbg(&client->dev, "probe error %d\n", err); | ||
656 | return err; | 644 | return err; |
657 | } | 645 | } |
658 | 646 | ||
@@ -667,8 +655,6 @@ static int at24_remove(struct i2c_client *client) | |||
667 | for (i = 1; i < at24->num_addresses; i++) | 655 | for (i = 1; i < at24->num_addresses; i++) |
668 | i2c_unregister_device(at24->client[i]); | 656 | i2c_unregister_device(at24->client[i]); |
669 | 657 | ||
670 | kfree(at24->writebuf); | ||
671 | kfree(at24); | ||
672 | return 0; | 658 | return 0; |
673 | } | 659 | } |
674 | 660 | ||