diff mbox series

usb: bluetooth: get lock before calling usb_[disable|enable]_autosuspend()

Message ID 20210802221429.GA1370657@pc
State New
Headers show
Series usb: bluetooth: get lock before calling usb_[disable|enable]_autosuspend() | expand

Commit Message

Salah Triki Aug. 2, 2021, 10:14 p.m. UTC
Based on the documentation of usb_[disable|enable]_autosuspend(), the
caller must hold udev's device lock.

Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
 drivers/bluetooth/btusb.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

gregkh@linuxfoundation.org Aug. 3, 2021, 5:37 a.m. UTC | #1
On Mon, Aug 02, 2021 at 11:14:29PM +0100, Salah Triki wrote:
> Based on the documentation of usb_[disable|enable]_autosuspend(), the

> caller must hold udev's device lock.

> 

> Signed-off-by: Salah Triki <salah.triki@gmail.com>

> ---

>  drivers/bluetooth/btusb.c | 5 ++++-

>  1 file changed, 4 insertions(+), 1 deletion(-)

> 

> diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c

> index a9855a2dd561..2ceb48164b6d 100644

> --- a/drivers/bluetooth/btusb.c

> +++ b/drivers/bluetooth/btusb.c

> @@ -1939,8 +1939,11 @@ static int btusb_setup_csr(struct hci_dev *hdev)

>  

>  			device_set_wakeup_capable(&data->udev->dev, false);

>  			/* Re-enable autosuspend if this was requested */

> -			if (enable_autosuspend)

> +			if (enable_autosuspend) {

> +				usb_lock_device(data->udev);

>  				usb_enable_autosuspend(data->udev);

> +				usb_unlock_device(data->udev);

> +			}

>  		}

>  	}

>  

> -- 

> 2.25.1

> 


As was pointed out elsewhere, this is not correct.

thanks,

greg k-h
diff mbox series

Patch

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index a9855a2dd561..2ceb48164b6d 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -1939,8 +1939,11 @@  static int btusb_setup_csr(struct hci_dev *hdev)
 
 			device_set_wakeup_capable(&data->udev->dev, false);
 			/* Re-enable autosuspend if this was requested */
-			if (enable_autosuspend)
+			if (enable_autosuspend) {
+				usb_lock_device(data->udev);
 				usb_enable_autosuspend(data->udev);
+				usb_unlock_device(data->udev);
+			}
 		}
 	}