Commit 45bf39f8 authored by Alan Stern's avatar Alan Stern Committed by Greg Kroah-Hartman

USB: core: Don't hold device lock while reading the "descriptors" sysfs file

Ever since commit 83e83ecb ("usb: core: get config and string
descriptors for unauthorized devices") was merged in 2013, there has
been no mechanism for reallocating the rawdescriptors buffers in
struct usb_device after the initial enumeration.  Before that commit,
the buffers would be deallocated when a device was deauthorized and
reallocated when it was authorized and enumerated.

This means that the locking in the read_descriptors() routine is not
needed, since the buffers it reads will never be reallocated while the
routine is running.  This locking can interfere with user programs
trying to read a hub's descriptors via sysfs while new child devices
of the hub are being initialized, since the hub is locked during this
procedure.

Since the locking in read_descriptors() hasn't been needed for over
nine years, we can remove it.
Reported-and-tested-by: default avatarTroels Liebe Bentsen <troels@connectedcars.dk>
Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
CC: stable@vger.kernel.org
Link: https://lore.kernel.org/r/Y9l+wDTRbuZABzsE@rowland.harvard.eduSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 49814e2c
...@@ -2389,9 +2389,8 @@ static int usb_enumerate_device_otg(struct usb_device *udev) ...@@ -2389,9 +2389,8 @@ static int usb_enumerate_device_otg(struct usb_device *udev)
* usb_enumerate_device - Read device configs/intfs/otg (usbcore-internal) * usb_enumerate_device - Read device configs/intfs/otg (usbcore-internal)
* @udev: newly addressed device (in ADDRESS state) * @udev: newly addressed device (in ADDRESS state)
* *
* This is only called by usb_new_device() and usb_authorize_device() * This is only called by usb_new_device() -- all comments that apply there
* and FIXME -- all comments that apply to them apply here wrt to * apply here wrt to environment.
* environment.
* *
* If the device is WUSB and not authorized, we don't attempt to read * If the device is WUSB and not authorized, we don't attempt to read
* the string descriptors, as they will be errored out by the device * the string descriptors, as they will be errored out by the device
......
...@@ -869,11 +869,7 @@ read_descriptors(struct file *filp, struct kobject *kobj, ...@@ -869,11 +869,7 @@ read_descriptors(struct file *filp, struct kobject *kobj,
size_t srclen, n; size_t srclen, n;
int cfgno; int cfgno;
void *src; void *src;
int retval;
retval = usb_lock_device_interruptible(udev);
if (retval < 0)
return -EINTR;
/* The binary attribute begins with the device descriptor. /* The binary attribute begins with the device descriptor.
* Following that are the raw descriptor entries for all the * Following that are the raw descriptor entries for all the
* configurations (config plus subsidiary descriptors). * configurations (config plus subsidiary descriptors).
...@@ -898,7 +894,6 @@ read_descriptors(struct file *filp, struct kobject *kobj, ...@@ -898,7 +894,6 @@ read_descriptors(struct file *filp, struct kobject *kobj,
off -= srclen; off -= srclen;
} }
} }
usb_unlock_device(udev);
return count - nleft; return count - nleft;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment