Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Alan Stern and committed by
Greg Kroah-Hartman
dd865571 7ed92f1a

+7
+7
drivers/usb/core/sysfs.c
··· 232 232 int len = count; 233 233 char *cp; 234 234 int rc = 0; 235 + int old_autosuspend_disabled, old_autoresume_disabled; 235 236 236 237 cp = memchr(buf, '\n', count); 237 238 if (cp) 238 239 len = cp - buf; 239 240 240 241 usb_lock_device(udev); 242 + old_autosuspend_disabled = udev->autosuspend_disabled; 243 + old_autoresume_disabled = udev->autoresume_disabled; 241 244 242 245 /* Setting the flags without calling usb_pm_lock is a subject to 243 246 * races, but who cares... ··· 266 263 } else 267 264 rc = -EINVAL; 268 265 266 + if (rc) { 267 + udev->autosuspend_disabled = old_autosuspend_disabled; 268 + udev->autoresume_disabled = old_autoresume_disabled; 269 + } 269 270 usb_unlock_device(udev); 270 271 return (rc < 0 ? rc : count); 271 272 }