linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: misc: chaoskey: get lock before calling usb_[disable|enable]_autosuspend()
@ 2021-08-02 22:22 Salah Triki
  2021-08-03  0:58 ` Alan Stern
  0 siblings, 1 reply; 2+ messages in thread
From: Salah Triki @ 2021-08-02 22:22 UTC (permalink / raw)
  To: Keith Packard, Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel

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/usb/misc/chaoskey.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/misc/chaoskey.c b/drivers/usb/misc/chaoskey.c
index 87067c3d6109..8af00be7b9e8 100644
--- a/drivers/usb/misc/chaoskey.c
+++ b/drivers/usb/misc/chaoskey.c
@@ -206,7 +206,9 @@ static int chaoskey_probe(struct usb_interface *interface,
 	if (!dev->hwrng_registered)
 		usb_err(interface, "Unable to register with hwrng");
 
+	usb_lock_device(udev);
 	usb_enable_autosuspend(udev);
+	usb_unlock_device(udev);
 
 	usb_dbg(interface, "chaoskey probe success, size %d", dev->size);
 	return 0;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] usb: misc: chaoskey: get lock before calling usb_[disable|enable]_autosuspend()
  2021-08-02 22:22 [PATCH] usb: misc: chaoskey: get lock before calling usb_[disable|enable]_autosuspend() Salah Triki
@ 2021-08-03  0:58 ` Alan Stern
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Stern @ 2021-08-03  0:58 UTC (permalink / raw)
  To: Salah Triki; +Cc: Keith Packard, Greg Kroah-Hartman, linux-usb, linux-kernel

On Mon, Aug 02, 2021 at 11:22:05PM +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/usb/misc/chaoskey.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/usb/misc/chaoskey.c b/drivers/usb/misc/chaoskey.c
> index 87067c3d6109..8af00be7b9e8 100644
> --- a/drivers/usb/misc/chaoskey.c
> +++ b/drivers/usb/misc/chaoskey.c
> @@ -206,7 +206,9 @@ static int chaoskey_probe(struct usb_interface *interface,
>  	if (!dev->hwrng_registered)
>  		usb_err(interface, "Unable to register with hwrng");
>  
> +	usb_lock_device(udev);
>  	usb_enable_autosuspend(udev);
> +	usb_unlock_device(udev);

Not needed (indeed, actively harmful).  When this code runs it already 
holds the device lock, because it is part of a probe routine.

Alan Stern

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-03  0:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-02 22:22 [PATCH] usb: misc: chaoskey: get lock before calling usb_[disable|enable]_autosuspend() Salah Triki
2021-08-03  0:58 ` Alan Stern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).