Commit f0ac23639c62add367309101d18ae2aa1d4a377c
Committed by
Greg Kroah-Hartman
1 parent
84524cf43d
Exists in
smarc-imx_3.14.28_1.0.0_ga
and in
1 other branch
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>
Showing 1 changed file with 15 additions and 29 deletions Side-by-side Diff
drivers/misc/eeprom/at24.c
... | ... | @@ -492,10 +492,9 @@ |
492 | 492 | if (client->dev.platform_data) { |
493 | 493 | chip = *(struct at24_platform_data *)client->dev.platform_data; |
494 | 494 | } else { |
495 | - if (!id->driver_data) { | |
496 | - err = -ENODEV; | |
497 | - goto err_out; | |
498 | - } | |
495 | + if (!id->driver_data) | |
496 | + return -ENODEV; | |
497 | + | |
499 | 498 | magic = id->driver_data; |
500 | 499 | chip.byte_len = BIT(magic & AT24_BITMASK(AT24_SIZE_BYTELEN)); |
501 | 500 | magic >>= AT24_SIZE_BYTELEN; |
... | ... | @@ -519,8 +518,7 @@ |
519 | 518 | "byte_len looks suspicious (no power of 2)!\n"); |
520 | 519 | if (!chip.page_size) { |
521 | 520 | dev_err(&client->dev, "page_size must not be 0!\n"); |
522 | - err = -EINVAL; | |
523 | - goto err_out; | |
521 | + return -EINVAL; | |
524 | 522 | } |
525 | 523 | if (!is_power_of_2(chip.page_size)) |
526 | 524 | dev_warn(&client->dev, |
... | ... | @@ -528,10 +526,9 @@ |
528 | 526 | |
529 | 527 | /* Use I2C operations unless we're stuck with SMBus extensions. */ |
530 | 528 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { |
531 | - if (chip.flags & AT24_FLAG_ADDR16) { | |
532 | - err = -EPFNOSUPPORT; | |
533 | - goto err_out; | |
534 | - } | |
529 | + if (chip.flags & AT24_FLAG_ADDR16) | |
530 | + return -EPFNOSUPPORT; | |
531 | + | |
535 | 532 | if (i2c_check_functionality(client->adapter, |
536 | 533 | I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { |
537 | 534 | use_smbus = I2C_SMBUS_I2C_BLOCK_DATA; |
... | ... | @@ -542,8 +539,7 @@ |
542 | 539 | I2C_FUNC_SMBUS_READ_BYTE_DATA)) { |
543 | 540 | use_smbus = I2C_SMBUS_BYTE_DATA; |
544 | 541 | } else { |
545 | - err = -EPFNOSUPPORT; | |
546 | - goto err_out; | |
542 | + return -EPFNOSUPPORT; | |
547 | 543 | } |
548 | 544 | } |
549 | 545 | |
550 | 546 | |
... | ... | @@ -553,12 +549,10 @@ |
553 | 549 | num_addresses = DIV_ROUND_UP(chip.byte_len, |
554 | 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 | 553 | num_addresses * sizeof(struct i2c_client *), GFP_KERNEL); |
558 | - if (!at24) { | |
559 | - err = -ENOMEM; | |
560 | - goto err_out; | |
561 | - } | |
554 | + if (!at24) | |
555 | + return -ENOMEM; | |
562 | 556 | |
563 | 557 | mutex_init(&at24->lock); |
564 | 558 | at24->use_smbus = use_smbus; |
... | ... | @@ -596,11 +590,10 @@ |
596 | 590 | at24->write_max = write_max; |
597 | 591 | |
598 | 592 | /* buffer (data + address at the beginning) */ |
599 | - at24->writebuf = kmalloc(write_max + 2, GFP_KERNEL); | |
600 | - if (!at24->writebuf) { | |
601 | - err = -ENOMEM; | |
602 | - goto err_struct; | |
603 | - } | |
593 | + at24->writebuf = devm_kzalloc(&client->dev, | |
594 | + write_max + 2, GFP_KERNEL); | |
595 | + if (!at24->writebuf) | |
596 | + return -ENOMEM; | |
604 | 597 | } else { |
605 | 598 | dev_warn(&client->dev, |
606 | 599 | "cannot write due to controller restrictions."); |
... | ... | @@ -648,11 +641,6 @@ |
648 | 641 | if (at24->client[i]) |
649 | 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 | 644 | return err; |
657 | 645 | } |
658 | 646 | |
... | ... | @@ -667,8 +655,6 @@ |
667 | 655 | for (i = 1; i < at24->num_addresses; i++) |
668 | 656 | i2c_unregister_device(at24->client[i]); |
669 | 657 | |
670 | - kfree(at24->writebuf); | |
671 | - kfree(at24); | |
672 | 658 | return 0; |
673 | 659 | } |
674 | 660 |