[PATCH v2 3/3] Bluetooth: btusb: clean up probe error handling
From: Johan Hovold
Date: Thu Apr 02 2026 - 05:33:36 EST
Clean up probe error handling by using dedicated error labels with an
"err" prefix.
Note that the endpoint lookup helper returns -ENXIO when endpoints are
missing which is functionally equivalent to returning -ENODEV.
Signed-off-by: Johan Hovold <johan@xxxxxxxxxx>
---
drivers/bluetooth/btusb.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 0001477463a3..28e2a536a309 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -4055,10 +4055,8 @@ static int btusb_probe(struct usb_interface *intf,
err = usb_find_common_endpoints(intf->cur_altsetting, &data->bulk_rx_ep,
&data->bulk_tx_ep, &data->intr_ep, NULL);
- if (err) {
- kfree(data);
- return -ENODEV;
- }
+ if (err)
+ goto err_free_data;
if (id->driver_info & BTUSB_AMP) {
data->cmdreq_type = USB_TYPE_CLASS | 0x01;
@@ -4114,8 +4112,8 @@ static int btusb_probe(struct usb_interface *intf,
hdev = hci_alloc_dev_priv(priv_size);
if (!hdev) {
- kfree(data);
- return -ENOMEM;
+ err = -ENOMEM;
+ goto err_free_data;
}
hdev->bus = HCI_USB;
@@ -4129,7 +4127,7 @@ static int btusb_probe(struct usb_interface *intf,
GPIOD_OUT_LOW);
if (IS_ERR(reset_gpio)) {
err = PTR_ERR(reset_gpio);
- goto out_free_dev;
+ goto err_free_hdev;
} else if (reset_gpio) {
data->reset_gpio = reset_gpio;
}
@@ -4145,7 +4143,7 @@ static int btusb_probe(struct usb_interface *intf,
#ifdef CONFIG_PM
err = btusb_config_oob_wake(hdev);
if (err)
- goto out_free_dev;
+ goto err_put_reset;
/* Marvell devices may need a specific chip configuration */
if (id->driver_info & BTUSB_MARVELL && data->oob_wake_irq) {
@@ -4391,11 +4389,14 @@ static int btusb_probe(struct usb_interface *intf,
device_init_wakeup(&data->udev->dev, false);
free_irq(data->oob_wake_irq, data);
}
-out_free_dev:
+err_put_reset:
if (data->reset_gpio)
gpiod_put(data->reset_gpio);
+err_free_hdev:
hci_free_dev(hdev);
+err_free_data:
kfree(data);
+
return err;
}
--
2.52.0