Skip to content

Commit e9087e8

Browse files
diandersVudentz
authored andcommitted
Bluetooth: btusb: mediatek: Add locks for usb_driver_claim_interface()
The documentation for usb_driver_claim_interface() says that "the device lock" is needed when the function is called from places other than probe(). This appears to be the lock for the USB interface device. The Mediatek btusb code gets called via this path: Workqueue: hci0 hci_power_on [bluetooth] Call trace: usb_driver_claim_interface btusb_mtk_claim_iso_intf btusb_mtk_setup hci_dev_open_sync hci_power_on process_scheduled_works worker_thread kthread With the above call trace the device lock hasn't been claimed. Claim it. Without this fix, we'd sometimes see the error "Failed to claim iso interface". Sometimes we'd even see worse errors, like a NULL pointer dereference (where `intf->dev.driver` was NULL) with a trace like: Call trace: usb_suspend_both usb_runtime_suspend __rpm_callback rpm_suspend pm_runtime_work process_scheduled_works Both errors appear to be fixed with the proper locking. Fixes: ceac1cb ("Bluetooth: btusb: mediatek: add ISO data transmission functions") Signed-off-by: Douglas Anderson <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 9e6c4e6 commit e9087e8

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

drivers/bluetooth/btusb.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,8 +2639,15 @@ static void btusb_mtk_claim_iso_intf(struct btusb_data *data)
26392639
struct btmtk_data *btmtk_data = hci_get_priv(data->hdev);
26402640
int err;
26412641

2642+
/*
2643+
* The function usb_driver_claim_interface() is documented to need
2644+
* locks held if it's not called from a probe routine. The code here
2645+
* is called from the hci_power_on workqueue, so grab the lock.
2646+
*/
2647+
device_lock(&btmtk_data->isopkt_intf->dev);
26422648
err = usb_driver_claim_interface(&btusb_driver,
26432649
btmtk_data->isopkt_intf, data);
2650+
device_unlock(&btmtk_data->isopkt_intf->dev);
26442651
if (err < 0) {
26452652
btmtk_data->isopkt_intf = NULL;
26462653
bt_dev_err(data->hdev, "Failed to claim iso interface");

0 commit comments

Comments
 (0)