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

firewire: core: use cleanup function to release cached configuration ROM

When returning from read_config_rom() function, the allocated buffer and
the previous buffer for configuration ROM should be released. The cleanup
function is useful in the case.

This commit uses the cleanup function to remove goto statements.

Link: https://lore.kernel.org/r/20251020115810.92839-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>

+12 -22
+12 -22
drivers/firewire/core-device.c
··· 653 653 static int read_config_rom(struct fw_device *device, int generation) 654 654 { 655 655 struct fw_card *card = device->card; 656 - const u32 *old_rom, *new_rom; 657 - u32 *rom, *stack; 656 + const u32 *new_rom, *old_rom __free(kfree) = NULL; 657 + u32 *stack, *rom __free(kfree) = NULL; 658 658 u32 sp, key; 659 659 int i, end, length, ret, speed; 660 660 int quirks; ··· 673 673 for (i = 0; i < 5; i++) { 674 674 ret = read_rom(device, generation, speed, i, &rom[i]); 675 675 if (ret != RCODE_COMPLETE) 676 - goto out; 676 + return ret; 677 677 /* 678 678 * As per IEEE1212 7.2, during initialization, devices can 679 679 * reply with a 0 for the first quadlet of the config ··· 682 682 * harddisk). In that case we just fail, and the 683 683 * retry mechanism will try again later. 684 684 */ 685 - if (i == 0 && rom[i] == 0) { 686 - ret = RCODE_BUSY; 687 - goto out; 688 - } 685 + if (i == 0 && rom[i] == 0) 686 + return RCODE_BUSY; 689 687 } 690 688 691 689 quirks = detect_quirks_by_bus_information_block(rom); ··· 710 712 */ 711 713 key = stack[--sp]; 712 714 i = key & 0xffffff; 713 - if (WARN_ON(i >= MAX_CONFIG_ROM_SIZE)) { 714 - ret = -ENXIO; 715 - goto out; 716 - } 715 + if (WARN_ON(i >= MAX_CONFIG_ROM_SIZE)) 716 + return -ENXIO; 717 717 718 718 /* Read header quadlet for the block to get the length. */ 719 719 ret = read_rom(device, generation, speed, i, &rom[i]); 720 720 if (ret != RCODE_COMPLETE) 721 - goto out; 721 + return ret; 722 722 end = i + (rom[i] >> 16) + 1; 723 723 if (end > MAX_CONFIG_ROM_SIZE) { 724 724 /* ··· 740 744 for (; i < end; i++) { 741 745 ret = read_rom(device, generation, speed, i, &rom[i]); 742 746 if (ret != RCODE_COMPLETE) 743 - goto out; 747 + return ret; 744 748 745 749 if ((key >> 30) != 3 || (rom[i] >> 30) < 2) 746 750 continue; ··· 800 804 801 805 old_rom = device->config_rom; 802 806 new_rom = kmemdup(rom, length * 4, GFP_KERNEL); 803 - if (new_rom == NULL) { 804 - ret = -ENOMEM; 805 - goto out; 806 - } 807 + if (new_rom == NULL) 808 + return -ENOMEM; 807 809 808 810 scoped_guard(rwsem_write, &fw_device_rwsem) { 809 811 device->config_rom = new_rom; 810 812 device->config_rom_length = length; 811 813 } 812 814 813 - kfree(old_rom); 814 - ret = RCODE_COMPLETE; 815 815 device->max_rec = rom[2] >> 12 & 0xf; 816 816 device->cmc = rom[2] >> 30 & 1; 817 817 device->irmc = rom[2] >> 31 & 1; 818 - out: 819 - kfree(rom); 820 818 821 - return ret; 819 + return RCODE_COMPLETE; 822 820 } 823 821 824 822 static void fw_unit_release(struct device *dev)