Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Nikolay Balandin and committed by
Greg Kroah-Hartman
f0ac2363 84524cf4

+15 -29
+15 -29
drivers/misc/eeprom/at24.c
··· 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; ··· 518 519 "byte_len looks suspicious (no power of 2)!\n"); 519 520 if (!chip.page_size) { 520 521 dev_err(&client->dev, "page_size must not be 0!\n"); 521 - err = -EINVAL; 522 - goto err_out; 522 + return -EINVAL; 523 523 } 524 524 if (!is_power_of_2(chip.page_size)) 525 525 dev_warn(&client->dev, ··· 526 528 527 529 /* Use I2C operations unless we're stuck with SMBus extensions. */ 528 530 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 529 - if (chip.flags & AT24_FLAG_ADDR16) { 530 - err = -EPFNOSUPPORT; 531 - goto err_out; 532 - } 531 + if (chip.flags & AT24_FLAG_ADDR16) 532 + return -EPFNOSUPPORT; 533 + 533 534 if (i2c_check_functionality(client->adapter, 534 535 I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { 535 536 use_smbus = I2C_SMBUS_I2C_BLOCK_DATA; ··· 539 542 I2C_FUNC_SMBUS_READ_BYTE_DATA)) { 540 543 use_smbus = I2C_SMBUS_BYTE_DATA; 541 544 } else { 542 - err = -EPFNOSUPPORT; 543 - goto err_out; 545 + return -EPFNOSUPPORT; 544 546 } 545 547 } 546 548 ··· 549 553 num_addresses = DIV_ROUND_UP(chip.byte_len, 550 554 (chip.flags & AT24_FLAG_ADDR16) ? 65536 : 256); 551 555 552 - at24 = kzalloc(sizeof(struct at24_data) + 556 + at24 = devm_kzalloc(&client->dev, sizeof(struct at24_data) + 553 557 num_addresses * sizeof(struct i2c_client *), GFP_KERNEL); 554 - if (!at24) { 555 - err = -ENOMEM; 556 - goto err_out; 557 - } 558 + if (!at24) 559 + return -ENOMEM; 558 560 559 561 mutex_init(&at24->lock); 560 562 at24->use_smbus = use_smbus; ··· 590 596 at24->write_max = write_max; 591 597 592 598 /* buffer (data + address at the beginning) */ 593 - at24->writebuf = kmalloc(write_max + 2, GFP_KERNEL); 594 - if (!at24->writebuf) { 595 - err = -ENOMEM; 596 - goto err_struct; 597 - } 599 + at24->writebuf = devm_kzalloc(&client->dev, 600 + write_max + 2, GFP_KERNEL); 601 + if (!at24->writebuf) 602 + return -ENOMEM; 598 603 } else { 599 604 dev_warn(&client->dev, 600 605 "cannot write due to controller restrictions."); ··· 641 648 if (at24->client[i]) 642 649 i2c_unregister_device(at24->client[i]); 643 650 644 - kfree(at24->writebuf); 645 - err_struct: 646 - kfree(at24); 647 - err_out: 648 - dev_dbg(&client->dev, "probe error %d\n", err); 649 651 return err; 650 652 } 651 653 ··· 655 667 for (i = 1; i < at24->num_addresses; i++) 656 668 i2c_unregister_device(at24->client[i]); 657 669 658 - kfree(at24->writebuf); 659 - kfree(at24); 660 670 return 0; 661 671 } 662 672