diff options
Diffstat (limited to 'drivers/usb/core/sysfs.c')
-rw-r--r-- | drivers/usb/core/sysfs.c | 68 |
1 files changed, 48 insertions, 20 deletions
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c index 65b6e6b84043..c953a0f1c695 100644 --- a/drivers/usb/core/sysfs.c +++ b/drivers/usb/core/sysfs.c | |||
@@ -23,10 +23,12 @@ static ssize_t field##_show(struct device *dev, \ | |||
23 | { \ | 23 | { \ |
24 | struct usb_device *udev; \ | 24 | struct usb_device *udev; \ |
25 | struct usb_host_config *actconfig; \ | 25 | struct usb_host_config *actconfig; \ |
26 | ssize_t rc = 0; \ | 26 | ssize_t rc; \ |
27 | \ | 27 | \ |
28 | udev = to_usb_device(dev); \ | 28 | udev = to_usb_device(dev); \ |
29 | usb_lock_device(udev); \ | 29 | rc = usb_lock_device_interruptible(udev); \ |
30 | if (rc < 0) \ | ||
31 | return -EINTR; \ | ||
30 | actconfig = udev->actconfig; \ | 32 | actconfig = udev->actconfig; \ |
31 | if (actconfig) \ | 33 | if (actconfig) \ |
32 | rc = sprintf(buf, format_string, \ | 34 | rc = sprintf(buf, format_string, \ |
@@ -47,10 +49,12 @@ static ssize_t bMaxPower_show(struct device *dev, | |||
47 | { | 49 | { |
48 | struct usb_device *udev; | 50 | struct usb_device *udev; |
49 | struct usb_host_config *actconfig; | 51 | struct usb_host_config *actconfig; |
50 | ssize_t rc = 0; | 52 | ssize_t rc; |
51 | 53 | ||
52 | udev = to_usb_device(dev); | 54 | udev = to_usb_device(dev); |
53 | usb_lock_device(udev); | 55 | rc = usb_lock_device_interruptible(udev); |
56 | if (rc < 0) | ||
57 | return -EINTR; | ||
54 | actconfig = udev->actconfig; | 58 | actconfig = udev->actconfig; |
55 | if (actconfig) | 59 | if (actconfig) |
56 | rc = sprintf(buf, "%dmA\n", usb_get_max_power(udev, actconfig)); | 60 | rc = sprintf(buf, "%dmA\n", usb_get_max_power(udev, actconfig)); |
@@ -64,10 +68,12 @@ static ssize_t configuration_show(struct device *dev, | |||
64 | { | 68 | { |
65 | struct usb_device *udev; | 69 | struct usb_device *udev; |
66 | struct usb_host_config *actconfig; | 70 | struct usb_host_config *actconfig; |
67 | ssize_t rc = 0; | 71 | ssize_t rc; |
68 | 72 | ||
69 | udev = to_usb_device(dev); | 73 | udev = to_usb_device(dev); |
70 | usb_lock_device(udev); | 74 | rc = usb_lock_device_interruptible(udev); |
75 | if (rc < 0) | ||
76 | return -EINTR; | ||
71 | actconfig = udev->actconfig; | 77 | actconfig = udev->actconfig; |
72 | if (actconfig && actconfig->string) | 78 | if (actconfig && actconfig->string) |
73 | rc = sprintf(buf, "%s\n", actconfig->string); | 79 | rc = sprintf(buf, "%s\n", actconfig->string); |
@@ -84,11 +90,13 @@ static ssize_t bConfigurationValue_store(struct device *dev, | |||
84 | const char *buf, size_t count) | 90 | const char *buf, size_t count) |
85 | { | 91 | { |
86 | struct usb_device *udev = to_usb_device(dev); | 92 | struct usb_device *udev = to_usb_device(dev); |
87 | int config, value; | 93 | int config, value, rc; |
88 | 94 | ||
89 | if (sscanf(buf, "%d", &config) != 1 || config < -1 || config > 255) | 95 | if (sscanf(buf, "%d", &config) != 1 || config < -1 || config > 255) |
90 | return -EINVAL; | 96 | return -EINVAL; |
91 | usb_lock_device(udev); | 97 | rc = usb_lock_device_interruptible(udev); |
98 | if (rc < 0) | ||
99 | return -EINTR; | ||
92 | value = usb_set_configuration(udev, config); | 100 | value = usb_set_configuration(udev, config); |
93 | usb_unlock_device(udev); | 101 | usb_unlock_device(udev); |
94 | return (value < 0) ? value : count; | 102 | return (value < 0) ? value : count; |
@@ -105,7 +113,9 @@ static ssize_t name##_show(struct device *dev, \ | |||
105 | int retval; \ | 113 | int retval; \ |
106 | \ | 114 | \ |
107 | udev = to_usb_device(dev); \ | 115 | udev = to_usb_device(dev); \ |
108 | usb_lock_device(udev); \ | 116 | retval = usb_lock_device_interruptible(udev); \ |
117 | if (retval < 0) \ | ||
118 | return -EINTR; \ | ||
109 | retval = sprintf(buf, "%s\n", udev->name); \ | 119 | retval = sprintf(buf, "%s\n", udev->name); \ |
110 | usb_unlock_device(udev); \ | 120 | usb_unlock_device(udev); \ |
111 | return retval; \ | 121 | return retval; \ |
@@ -141,6 +151,9 @@ static ssize_t speed_show(struct device *dev, struct device_attribute *attr, | |||
141 | case USB_SPEED_SUPER: | 151 | case USB_SPEED_SUPER: |
142 | speed = "5000"; | 152 | speed = "5000"; |
143 | break; | 153 | break; |
154 | case USB_SPEED_SUPER_PLUS: | ||
155 | speed = "10000"; | ||
156 | break; | ||
144 | default: | 157 | default: |
145 | speed = "unknown"; | 158 | speed = "unknown"; |
146 | } | 159 | } |
@@ -224,11 +237,13 @@ static ssize_t avoid_reset_quirk_store(struct device *dev, | |||
224 | const char *buf, size_t count) | 237 | const char *buf, size_t count) |
225 | { | 238 | { |
226 | struct usb_device *udev = to_usb_device(dev); | 239 | struct usb_device *udev = to_usb_device(dev); |
227 | int val; | 240 | int val, rc; |
228 | 241 | ||
229 | if (sscanf(buf, "%d", &val) != 1 || val < 0 || val > 1) | 242 | if (sscanf(buf, "%d", &val) != 1 || val < 0 || val > 1) |
230 | return -EINVAL; | 243 | return -EINVAL; |
231 | usb_lock_device(udev); | 244 | rc = usb_lock_device_interruptible(udev); |
245 | if (rc < 0) | ||
246 | return -EINTR; | ||
232 | if (val) | 247 | if (val) |
233 | udev->quirks |= USB_QUIRK_RESET; | 248 | udev->quirks |= USB_QUIRK_RESET; |
234 | else | 249 | else |
@@ -294,7 +309,7 @@ static ssize_t persist_store(struct device *dev, struct device_attribute *attr, | |||
294 | const char *buf, size_t count) | 309 | const char *buf, size_t count) |
295 | { | 310 | { |
296 | struct usb_device *udev = to_usb_device(dev); | 311 | struct usb_device *udev = to_usb_device(dev); |
297 | int value; | 312 | int value, rc; |
298 | 313 | ||
299 | /* Hubs are always enabled for USB_PERSIST */ | 314 | /* Hubs are always enabled for USB_PERSIST */ |
300 | if (udev->descriptor.bDeviceClass == USB_CLASS_HUB) | 315 | if (udev->descriptor.bDeviceClass == USB_CLASS_HUB) |
@@ -303,7 +318,9 @@ static ssize_t persist_store(struct device *dev, struct device_attribute *attr, | |||
303 | if (sscanf(buf, "%d", &value) != 1) | 318 | if (sscanf(buf, "%d", &value) != 1) |
304 | return -EINVAL; | 319 | return -EINVAL; |
305 | 320 | ||
306 | usb_lock_device(udev); | 321 | rc = usb_lock_device_interruptible(udev); |
322 | if (rc < 0) | ||
323 | return -EINTR; | ||
307 | udev->persist_enabled = !!value; | 324 | udev->persist_enabled = !!value; |
308 | usb_unlock_device(udev); | 325 | usb_unlock_device(udev); |
309 | return count; | 326 | return count; |
@@ -420,13 +437,16 @@ static ssize_t level_store(struct device *dev, struct device_attribute *attr, | |||
420 | int len = count; | 437 | int len = count; |
421 | char *cp; | 438 | char *cp; |
422 | int rc = count; | 439 | int rc = count; |
440 | int rv; | ||
423 | 441 | ||
424 | warn_level(); | 442 | warn_level(); |
425 | cp = memchr(buf, '\n', count); | 443 | cp = memchr(buf, '\n', count); |
426 | if (cp) | 444 | if (cp) |
427 | len = cp - buf; | 445 | len = cp - buf; |
428 | 446 | ||
429 | usb_lock_device(udev); | 447 | rv = usb_lock_device_interruptible(udev); |
448 | if (rv < 0) | ||
449 | return -EINTR; | ||
430 | 450 | ||
431 | if (len == sizeof on_string - 1 && | 451 | if (len == sizeof on_string - 1 && |
432 | strncmp(buf, on_string, len) == 0) | 452 | strncmp(buf, on_string, len) == 0) |
@@ -466,7 +486,9 @@ static ssize_t usb2_hardware_lpm_store(struct device *dev, | |||
466 | bool value; | 486 | bool value; |
467 | int ret; | 487 | int ret; |
468 | 488 | ||
469 | usb_lock_device(udev); | 489 | ret = usb_lock_device_interruptible(udev); |
490 | if (ret < 0) | ||
491 | return -EINTR; | ||
470 | 492 | ||
471 | ret = strtobool(buf, &value); | 493 | ret = strtobool(buf, &value); |
472 | 494 | ||
@@ -536,8 +558,11 @@ static ssize_t usb3_hardware_lpm_u1_show(struct device *dev, | |||
536 | { | 558 | { |
537 | struct usb_device *udev = to_usb_device(dev); | 559 | struct usb_device *udev = to_usb_device(dev); |
538 | const char *p; | 560 | const char *p; |
561 | int rc; | ||
539 | 562 | ||
540 | usb_lock_device(udev); | 563 | rc = usb_lock_device_interruptible(udev); |
564 | if (rc < 0) | ||
565 | return -EINTR; | ||
541 | 566 | ||
542 | if (udev->usb3_lpm_u1_enabled) | 567 | if (udev->usb3_lpm_u1_enabled) |
543 | p = "enabled"; | 568 | p = "enabled"; |
@@ -555,8 +580,11 @@ static ssize_t usb3_hardware_lpm_u2_show(struct device *dev, | |||
555 | { | 580 | { |
556 | struct usb_device *udev = to_usb_device(dev); | 581 | struct usb_device *udev = to_usb_device(dev); |
557 | const char *p; | 582 | const char *p; |
583 | int rc; | ||
558 | 584 | ||
559 | usb_lock_device(udev); | 585 | rc = usb_lock_device_interruptible(udev); |
586 | if (rc < 0) | ||
587 | return -EINTR; | ||
560 | 588 | ||
561 | if (udev->usb3_lpm_u2_enabled) | 589 | if (udev->usb3_lpm_u2_enabled) |
562 | p = "enabled"; | 590 | p = "enabled"; |
@@ -822,7 +850,6 @@ read_descriptors(struct file *filp, struct kobject *kobj, | |||
822 | * Following that are the raw descriptor entries for all the | 850 | * Following that are the raw descriptor entries for all the |
823 | * configurations (config plus subsidiary descriptors). | 851 | * configurations (config plus subsidiary descriptors). |
824 | */ | 852 | */ |
825 | usb_lock_device(udev); | ||
826 | for (cfgno = -1; cfgno < udev->descriptor.bNumConfigurations && | 853 | for (cfgno = -1; cfgno < udev->descriptor.bNumConfigurations && |
827 | nleft > 0; ++cfgno) { | 854 | nleft > 0; ++cfgno) { |
828 | if (cfgno < 0) { | 855 | if (cfgno < 0) { |
@@ -843,7 +870,6 @@ read_descriptors(struct file *filp, struct kobject *kobj, | |||
843 | off -= srclen; | 870 | off -= srclen; |
844 | } | 871 | } |
845 | } | 872 | } |
846 | usb_unlock_device(udev); | ||
847 | return count - nleft; | 873 | return count - nleft; |
848 | } | 874 | } |
849 | 875 | ||
@@ -969,7 +995,9 @@ static ssize_t supports_autosuspend_show(struct device *dev, | |||
969 | { | 995 | { |
970 | int s; | 996 | int s; |
971 | 997 | ||
972 | device_lock(dev); | 998 | s = device_lock_interruptible(dev); |
999 | if (s < 0) | ||
1000 | return -EINTR; | ||
973 | /* Devices will be autosuspended even when an interface isn't claimed */ | 1001 | /* Devices will be autosuspended even when an interface isn't claimed */ |
974 | s = (!dev->driver || to_usb_driver(dev->driver)->supports_autosuspend); | 1002 | s = (!dev->driver || to_usb_driver(dev->driver)->supports_autosuspend); |
975 | device_unlock(dev); | 1003 | device_unlock(dev); |