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

USB: handle errors in power/level attribute

This patch (as906) improves the error handling for the USB power/level
attribute file.  If an error occurs, the original power-level settings
will be restored.
Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 7ed92f1a
...@@ -232,12 +232,15 @@ set_level(struct device *dev, struct device_attribute *attr, ...@@ -232,12 +232,15 @@ set_level(struct device *dev, struct device_attribute *attr,
int len = count; int len = count;
char *cp; char *cp;
int rc = 0; int rc = 0;
int old_autosuspend_disabled, old_autoresume_disabled;
cp = memchr(buf, '\n', count); cp = memchr(buf, '\n', count);
if (cp) if (cp)
len = cp - buf; len = cp - buf;
usb_lock_device(udev); usb_lock_device(udev);
old_autosuspend_disabled = udev->autosuspend_disabled;
old_autoresume_disabled = udev->autoresume_disabled;
/* Setting the flags without calling usb_pm_lock is a subject to /* Setting the flags without calling usb_pm_lock is a subject to
* races, but who cares... * races, but who cares...
...@@ -263,6 +266,10 @@ set_level(struct device *dev, struct device_attribute *attr, ...@@ -263,6 +266,10 @@ set_level(struct device *dev, struct device_attribute *attr,
} else } else
rc = -EINVAL; rc = -EINVAL;
if (rc) {
udev->autosuspend_disabled = old_autosuspend_disabled;
udev->autoresume_disabled = old_autoresume_disabled;
}
usb_unlock_device(udev); usb_unlock_device(udev);
return (rc < 0 ? rc : count); return (rc < 0 ? rc : count);
} }
......
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