On 14/01/16 11:47, Oliver Neukum wrote:
232275a USB: fix substandard locking for the sysfs files
introduced needed locking into sysfs operations on USB devices
It, however, uses uninterruptible sleep and if the error
handling is on extreme cases of sleep lengths of 10s of seconds
are possible. Unless we are removing the device we should use
interruptible sleep.
Signed-off-by: Oliver Neukum <oneukum@xxxxxxxx>
---
drivers/usb/core/sysfs.c | 69 ++++++++++++++++++++++++++++++++++--------------
include/linux/device.h | 5 ++++
include/linux/usb.h | 7 ++---
3 files changed, 58 insertions(+), 23 deletions(-)
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 65b6e6b..69da1d5 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
<snipped>
@@ -815,14 +840,16 @@ read_descriptors(struct file *filp, struct kobject *kobj,
struct usb_device *udev = to_usb_device(dev);
size_t nleft = count;
size_t srclen, n;
- int cfgno;
+ int cfgno, rc;
void *src;
/* The binary attribute begins with the device descriptor.
* Following that are the raw descriptor entries for all the
* configurations (config plus subsidiary descriptors).
*/
- usb_lock_device(udev);
+ rc = usb_lock_device_interruptible(udev);
+ if (rc < 0)
+ return -EINTR;
for (cfgno = -1; cfgno < udev->descriptor.bNumConfigurations &&
nleft > 0; ++cfgno) {
if (cfgno < 0) {
In my opinion the locking in read_descriptors() is unnecessary and can
be safely removed. I believe this function should be non-blocking (as
per pre-kernel 3.13).
Unwanted blocking occurs when read_descriptors() is getting the
descriptor information from the allocated rawdescriptors structure of a
USB hub but a device connected to the hub is failing and the device is
being recovered.
This patch helps in the case where the userland application is being
terminated by Ctrl-C whilst a failing USB device is being recovered due
to communication failure which causes blocking to get the USB hub
descriptors information from memory.
Have you checked that the calling sysfs layer can handle the returned
error code of -EINTR ? What code handles that ?
Note that read_descriptors() gets called multiple times (I have seen 3
calls) per a single sysfs read.
Regards,
Dean
--
Dean Jenkins
Embedded Software Engineer
Linux Transportation Solutions
Mentor Embedded Software Division
Mentor Graphics (UK) Ltd.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html