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

usb: misc: ljca: Fix double free in error handling path

When auxiliary_device_add() returns error and then calls
auxiliary_device_uninit(), callback function ljca_auxdev_release
calls kfree(auxdev->dev.platform_data) to free the parameter data
of the function ljca_new_client_device. The callers of
ljca_new_client_device shouldn't call kfree() again
in the error handling path to free the platform data.

Fix this by cleaning up the redundant kfree() in all callers and
adding kfree() the passed in platform_data on errors which happen
before auxiliary_device_init() succeeds .

Fixes: acd6199f195d ("usb: Add support for Intel LJCA device")
Cc: stable <stable@kernel.org>
Signed-off-by: Yongzhi Liu <hyperlyzcs@gmail.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20240311125748.28198-1-hyperlyzcs@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Yongzhi Liu and committed by
Greg Kroah-Hartman
7c963196 f5e9bda0

+9 -13
+9 -13
drivers/usb/misc/usb-ljca.c
··· 518 518 int ret; 519 519 520 520 client = kzalloc(sizeof *client, GFP_KERNEL); 521 - if (!client) 521 + if (!client) { 522 + kfree(data); 522 523 return -ENOMEM; 524 + } 523 525 524 526 client->type = type; 525 527 client->id = id; ··· 537 535 auxdev->dev.release = ljca_auxdev_release; 538 536 539 537 ret = auxiliary_device_init(auxdev); 540 - if (ret) 538 + if (ret) { 539 + kfree(data); 541 540 goto err_free; 541 + } 542 542 543 543 ljca_auxdev_acpi_bind(adap, auxdev, adr, id); 544 544 ··· 594 590 valid_pin[i] = get_unaligned_le32(&desc->bank_desc[i].valid_pins); 595 591 bitmap_from_arr32(gpio_info->valid_pin_map, valid_pin, gpio_num); 596 592 597 - ret = ljca_new_client_device(adap, LJCA_CLIENT_GPIO, 0, "ljca-gpio", 593 + return ljca_new_client_device(adap, LJCA_CLIENT_GPIO, 0, "ljca-gpio", 598 594 gpio_info, LJCA_GPIO_ACPI_ADR); 599 - if (ret) 600 - kfree(gpio_info); 601 - 602 - return ret; 603 595 } 604 596 605 597 static int ljca_enumerate_i2c(struct ljca_adapter *adap) ··· 629 629 ret = ljca_new_client_device(adap, LJCA_CLIENT_I2C, i, 630 630 "ljca-i2c", i2c_info, 631 631 LJCA_I2C1_ACPI_ADR + i); 632 - if (ret) { 633 - kfree(i2c_info); 632 + if (ret) 634 633 return ret; 635 - } 636 634 } 637 635 638 636 return 0; ··· 667 669 ret = ljca_new_client_device(adap, LJCA_CLIENT_SPI, i, 668 670 "ljca-spi", spi_info, 669 671 LJCA_SPI1_ACPI_ADR + i); 670 - if (ret) { 671 - kfree(spi_info); 672 + if (ret) 672 673 return ret; 673 - } 674 674 } 675 675 676 676 return 0;