aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/core/sysfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/core/sysfs.c')
-rw-r--r--drivers/usb/core/sysfs.c25
1 files changed, 4 insertions, 21 deletions
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index ae763974be25..15477008b631 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -327,7 +327,6 @@ static DEVICE_ATTR(autosuspend, S_IRUGO | S_IWUSR,
327 327
328static const char on_string[] = "on"; 328static const char on_string[] = "on";
329static const char auto_string[] = "auto"; 329static const char auto_string[] = "auto";
330static const char suspend_string[] = "suspend";
331 330
332static ssize_t 331static ssize_t
333show_level(struct device *dev, struct device_attribute *attr, char *buf) 332show_level(struct device *dev, struct device_attribute *attr, char *buf)
@@ -335,13 +334,8 @@ show_level(struct device *dev, struct device_attribute *attr, char *buf)
335 struct usb_device *udev = to_usb_device(dev); 334 struct usb_device *udev = to_usb_device(dev);
336 const char *p = auto_string; 335 const char *p = auto_string;
337 336
338 if (udev->state == USB_STATE_SUSPENDED) { 337 if (udev->state != USB_STATE_SUSPENDED && udev->autosuspend_disabled)
339 if (udev->autoresume_disabled) 338 p = on_string;
340 p = suspend_string;
341 } else {
342 if (udev->autosuspend_disabled)
343 p = on_string;
344 }
345 return sprintf(buf, "%s\n", p); 339 return sprintf(buf, "%s\n", p);
346} 340}
347 341
@@ -353,7 +347,7 @@ set_level(struct device *dev, struct device_attribute *attr,
353 int len = count; 347 int len = count;
354 char *cp; 348 char *cp;
355 int rc = 0; 349 int rc = 0;
356 int old_autosuspend_disabled, old_autoresume_disabled; 350 int old_autosuspend_disabled;
357 351
358 cp = memchr(buf, '\n', count); 352 cp = memchr(buf, '\n', count);
359 if (cp) 353 if (cp)
@@ -361,7 +355,6 @@ set_level(struct device *dev, struct device_attribute *attr,
361 355
362 usb_lock_device(udev); 356 usb_lock_device(udev);
363 old_autosuspend_disabled = udev->autosuspend_disabled; 357 old_autosuspend_disabled = udev->autosuspend_disabled;
364 old_autoresume_disabled = udev->autoresume_disabled;
365 358
366 /* Setting the flags without calling usb_pm_lock is a subject to 359 /* Setting the flags without calling usb_pm_lock is a subject to
367 * races, but who cares... 360 * races, but who cares...
@@ -369,28 +362,18 @@ set_level(struct device *dev, struct device_attribute *attr,
369 if (len == sizeof on_string - 1 && 362 if (len == sizeof on_string - 1 &&
370 strncmp(buf, on_string, len) == 0) { 363 strncmp(buf, on_string, len) == 0) {
371 udev->autosuspend_disabled = 1; 364 udev->autosuspend_disabled = 1;
372 udev->autoresume_disabled = 0;
373 rc = usb_external_resume_device(udev, PMSG_USER_RESUME); 365 rc = usb_external_resume_device(udev, PMSG_USER_RESUME);
374 366
375 } else if (len == sizeof auto_string - 1 && 367 } else if (len == sizeof auto_string - 1 &&
376 strncmp(buf, auto_string, len) == 0) { 368 strncmp(buf, auto_string, len) == 0) {
377 udev->autosuspend_disabled = 0; 369 udev->autosuspend_disabled = 0;
378 udev->autoresume_disabled = 0;
379 rc = usb_external_resume_device(udev, PMSG_USER_RESUME); 370 rc = usb_external_resume_device(udev, PMSG_USER_RESUME);
380 371
381 } else if (len == sizeof suspend_string - 1 &&
382 strncmp(buf, suspend_string, len) == 0) {
383 udev->autosuspend_disabled = 0;
384 udev->autoresume_disabled = 1;
385 rc = usb_external_suspend_device(udev, PMSG_USER_SUSPEND);
386
387 } else 372 } else
388 rc = -EINVAL; 373 rc = -EINVAL;
389 374
390 if (rc) { 375 if (rc)
391 udev->autosuspend_disabled = old_autosuspend_disabled; 376 udev->autosuspend_disabled = old_autosuspend_disabled;
392 udev->autoresume_disabled = old_autoresume_disabled;
393 }
394 usb_unlock_device(udev); 377 usb_unlock_device(udev);
395 return (rc < 0 ? rc : count); 378 return (rc < 0 ? rc : count);
396} 379}