Skip to content

Commit

Permalink
USB: handle errors in power/level attribute
Browse files Browse the repository at this point in the history
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: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Alan Stern authored and Greg Kroah-Hartman committed May 23, 2007
1 parent 7ed92f1 commit dd86557
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions drivers/usb/core/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,15 @@ set_level(struct device *dev, struct device_attribute *attr,
int len = count;
char *cp;
int rc = 0;
int old_autosuspend_disabled, old_autoresume_disabled;

cp = memchr(buf, '\n', count);
if (cp)
len = cp - buf;

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
* races, but who cares...
Expand All @@ -263,6 +266,10 @@ set_level(struct device *dev, struct device_attribute *attr,
} else
rc = -EINVAL;

if (rc) {
udev->autosuspend_disabled = old_autosuspend_disabled;
udev->autoresume_disabled = old_autoresume_disabled;
}
usb_unlock_device(udev);
return (rc < 0 ? rc : count);
}
Expand Down

0 comments on commit dd86557

Please sign in to comment.