Skip to content

Commit 7c96319

Browse files
Yongzhi Liugregkh
authored andcommitted
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: acd6199 ("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>
1 parent f5e9bda commit 7c96319

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

drivers/usb/misc/usb-ljca.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,10 @@ static int ljca_new_client_device(struct ljca_adapter *adap, u8 type, u8 id,
518518
int ret;
519519

520520
client = kzalloc(sizeof *client, GFP_KERNEL);
521-
if (!client)
521+
if (!client) {
522+
kfree(data);
522523
return -ENOMEM;
524+
}
523525

524526
client->type = type;
525527
client->id = id;
@@ -535,8 +537,10 @@ static int ljca_new_client_device(struct ljca_adapter *adap, u8 type, u8 id,
535537
auxdev->dev.release = ljca_auxdev_release;
536538

537539
ret = auxiliary_device_init(auxdev);
538-
if (ret)
540+
if (ret) {
541+
kfree(data);
539542
goto err_free;
543+
}
540544

541545
ljca_auxdev_acpi_bind(adap, auxdev, adr, id);
542546

@@ -590,12 +594,8 @@ static int ljca_enumerate_gpio(struct ljca_adapter *adap)
590594
valid_pin[i] = get_unaligned_le32(&desc->bank_desc[i].valid_pins);
591595
bitmap_from_arr32(gpio_info->valid_pin_map, valid_pin, gpio_num);
592596

593-
ret = ljca_new_client_device(adap, LJCA_CLIENT_GPIO, 0, "ljca-gpio",
597+
return ljca_new_client_device(adap, LJCA_CLIENT_GPIO, 0, "ljca-gpio",
594598
gpio_info, LJCA_GPIO_ACPI_ADR);
595-
if (ret)
596-
kfree(gpio_info);
597-
598-
return ret;
599599
}
600600

601601
static int ljca_enumerate_i2c(struct ljca_adapter *adap)
@@ -629,10 +629,8 @@ static int ljca_enumerate_i2c(struct ljca_adapter *adap)
629629
ret = ljca_new_client_device(adap, LJCA_CLIENT_I2C, i,
630630
"ljca-i2c", i2c_info,
631631
LJCA_I2C1_ACPI_ADR + i);
632-
if (ret) {
633-
kfree(i2c_info);
632+
if (ret)
634633
return ret;
635-
}
636634
}
637635

638636
return 0;
@@ -669,10 +667,8 @@ static int ljca_enumerate_spi(struct ljca_adapter *adap)
669667
ret = ljca_new_client_device(adap, LJCA_CLIENT_SPI, i,
670668
"ljca-spi", spi_info,
671669
LJCA_SPI1_ACPI_ADR + i);
672-
if (ret) {
673-
kfree(spi_info);
670+
if (ret)
674671
return ret;
675-
}
676672
}
677673

678674
return 0;

0 commit comments

Comments
 (0)