Bluetooth: btusb: fix wakeup irq devres lifetime
Subsystems (2)
v2 cover Bluetooth: btusb: fix wakeup irq devres lifetime
This series fixes a wakeup source leak and a (currently benign) OOB wakeup interrupt devres lifetime issue.
Included is also a related cleanup.
Note that these are intended for 7.1 (e.g. as the fixes are not critical) and apply on top of linux-next which has commit 2db5a8b68e31 ("Bluetooth: btusb: refactor endpoint lookup").
Johan
Changes in v2:
- fix wakeup source leak (new patch)
- fix disconnect-while-suspended issue by making interrupt non-managed
- amend devres lifetime fix commit message with a reference to changed devres behaviour
- clean up error handling (new patch)
Johan Hovold (3):
Bluetooth: btusb: fix wakeup source leak on probe failure
Bluetooth: btusb: fix wakeup irq devres lifetime
Bluetooth: btusb: clean up probe error handling
drivers/bluetooth/btusb.c | 50 +++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 18 deletions(-)
Signature · 1 line
2.52.0
PATCH v2 1/3 Bluetooth: btusb: fix wakeup source leak on probe failure
Make sure to disable wakeup on probe failure to avoid leaking the wakeup source.
--- drivers/bluetooth/btusb.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/bluetooth/btusb.c +8 -5
@@ -4146,7 +4146,7 @@ static int btusb_probe(struct usb_interface *intf,if (id->driver_info &BTUSB_MARVELL && data->oob_wake_irq) { err =marvell_config_oob_wake (hdev);if (err) - goto out_free_dev; + goto err_disable_wakeup; }#endif if (id->driver_info &BTUSB_CW6622 )
@@ -4183,7 +4183,7 @@ static int btusb_probe(struct usb_interface *intf,if (id->driver_info &BTUSB_INTEL_COMBINED ) { err =btintel_configure_setup (hdev, btusb_driver.name);if (err) - goto out_free_dev; + goto err_disable_wakeup;/* Transport specific configuration */ hdev->send = btusb_send_frame_intel;
@@ -4346,7 +4346,7 @@ static int btusb_probe(struct usb_interface *intf, err =usb_set_interface (data->udev,0 ,0 );if (err <0 ) {BT_ERR ("failed to set interface 0, alt 0 %d" , err); - goto out_free_dev; + goto err_disable_wakeup; } }
@@ -4354,7 +4354,7 @@ static int btusb_probe(struct usb_interface *intf, err =usb_driver_claim_interface (&btusb_driver, data->isoc, data);if (err <0 ) - goto out_free_dev; + goto err_disable_wakeup; }if (IS_ENABLED (CONFIG_BT_HCIBTUSB_BCM ) && data->diag) {
@@ -4372,7 +4372,7 @@ static int btusb_probe(struct usb_interface *intf, err =hci_register_dev (hdev);if (err <0 ) - goto out_free_dev; + goto err_disable_wakeup;usb_set_intfdata (intf, data);
@@ -4381,6 +4381,9 @@ static int btusb_probe(struct usb_interface *intf,return 0 ; +err_disable_wakeup: +if (data->oob_wake_irq) +device_init_wakeup (&data->udev->dev, false); out_free_dev:if (data->reset_gpio)gpiod_put (data->reset_gpio);
Signature · 1 line
2.52.0
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1076322
---Test result---
Test Summary:
CheckPatch PENDING 0.34 seconds GitLint PENDING 0.29 seconds SubjectPrefix PASS 0.33 seconds BuildKernel PASS 26.00 seconds CheckAllWarning PASS 28.76 seconds CheckSparse PASS 28.08 seconds BuildKernel32 PASS 25.80 seconds TestRunnerSetup PASS 568.36 seconds TestRunner_l2cap-tester PASS 28.28 seconds TestRunner_iso-tester PASS 44.15 seconds TestRunner_bnep-tester PASS 6.58 seconds TestRunner_mgmt-tester FAIL 117.31 seconds TestRunner_rfcomm-tester PASS 9.70 seconds TestRunner_sco-tester FAIL 14.50 seconds TestRunner_ioctl-tester PASS 10.31 seconds TestRunner_mesh-tester FAIL 12.76 seconds TestRunner_smp-tester PASS 8.81 seconds TestRunner_userchan-tester PASS 6.80 seconds IncrementalBuild PENDING 0.42 seconds
Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:
##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner Output:
Total: 494, Passed: 489 (99.0%), Failed: 1, Not Run: 4
Failed Test Cases
Read Exp Feature - Success Failed 0.104 seconds
##############################
Test: TestRunner_sco-tester - FAIL
Desc: Run sco-tester with test-runner
Output:
WARNING: possible circular locking dependency detected
BUG: sleeping function called from invalid context at net/core/sock.c:3782
Total: 30, Passed: 30 (100.0%), Failed: 0, Not Run: 0
##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner Output:
Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0
Failed Test Cases
Mesh - Send cancel - 1 Timed out 2.662 seconds Mesh - Send cancel - 2 Timed out 1.996 seconds
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:
---
Regards,
Linux Bluetooth
PATCH v2 2/3 Bluetooth: btusb: fix wakeup irq devres lifetime
In reply to Johan HovoldThe OOB wakeup irq is device managed but its lifetime is incorrectly tied to the child HCI device rather than the USB interface to which the driver is bound.
This should not cause any trouble currently as the interrupt will be disabled when the HCI device is deregistered on disconnect (but this was not always the case, see [1]), and there should be no further references if probe fails before registering it. But it is still technically wrong as the reference counted HCI device could in theory remain after a probe failure.
Explicitly free the interrupt on disconnect so that it is guaranteed to be disabled before freeing the (non-managed) driver data (including if disconnected while suspended).
[1] 699fb50d9903 ("drivers: base: Free devm resources when unregistering a device")
--- drivers/bluetooth/btusb.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
drivers/bluetooth/btusb.c +15 -5
@@ -3784,8 +3784,7 @@ static int btusb_config_oob_wake(struct hci_dev *hdev) }irq_set_status_flags (irq,IRQ_NOAUTOEN ); - ret =devm_request_irq (&hdev->dev, irq, btusb_oob_wake_handler, -0 ,"OOB Wake-on-BT" , data); + ret =request_irq (irq, btusb_oob_wake_handler,0 ,"OOB Wake-on-BT" , data);if (ret) {bt_dev_err (hdev,"%s: IRQ request failed" , __func__);return ret;
@@ -3794,12 +3793,18 @@ static int btusb_config_oob_wake(struct hci_dev *hdev) ret =device_init_wakeup (dev, true);if (ret) {bt_dev_err (hdev,"%s: failed to init_wakeup" , __func__); -return ret; + goto err_free_irq; } data->oob_wake_irq = irq;bt_dev_info (hdev,"OOB Wake-on-BT configured at IRQ %u" , irq); +return 0 ; + +err_free_irq: +free_irq (irq, data); + + return ret; }#endif
@@ -4382,8 +4387,10 @@ static int btusb_probe(struct usb_interface *intf,return 0 ; err_disable_wakeup: -if (data->oob_wake_irq) +if (data->oob_wake_irq) {device_init_wakeup (&data->udev->dev, false); +free_irq (data->oob_wake_irq, data); + } out_free_dev:if (data->reset_gpio)gpiod_put (data->reset_gpio);
@@ -4416,8 +4423,11 @@ static void btusb_disconnect(struct usb_interface *intf)hci_unregister_dev (hdev); -if (data->oob_wake_irq) +if (data->oob_wake_irq) {device_init_wakeup (&data->udev->dev, false); +free_irq (data->oob_wake_irq, data); + } +if (data->reset_gpio)gpiod_put (data->reset_gpio);
Signature · 1 line
2.52.0
PATCH v2 3/3 Bluetooth: btusb: clean up probe error handling
In reply to Johan HovoldClean 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.
--- drivers/bluetooth/btusb.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/bluetooth/btusb.c +10 -9
@@ -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; }
Signature · 1 line
2.52.0
Quoted 16 lines · Johan Hovold
This series fixes a wakeup source leak and a (currently benign) OOB wakeup interrupt devres lifetime issue.
Included is also a related cleanup.
Note that these are intended for 7.1 (e.g. as the fixes are not critical) and apply on top of linux-next which has commit
2db5a8b68e31("Bluetooth: btusb: refactor endpoint lookup").Changes in v2:
- fix wakeup source leak (new patch)
- fix disconnect-while-suspended issue by making interrupt non-managed
- amend devres lifetime fix commit message with a reference to changed devres behaviour
- clean up error handling (new patch)
Quoted 4 lines
Johan Hovold (3):
Bluetooth: btusb: fix wakeup source leak on probe failure
Bluetooth: btusb: fix wakeup irq devres lifetime
Bluetooth: btusb: clean up probe error handling
Sashiko reported two pre-existing bugs related to these paths and I can can take a look at fixing those as part of this series:
https://sashiko.dev/#/message/20260402092704.2346710-2-johan%40kernel.org
So please hold off with applying this one for a bit.
Johan