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

[PATCH] Fix Userspace interface breakage in power/state

Prevent passing invalid values down to the drivers.

Signed-off-by: Pavel Machek <pavel@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Pavel Machek and committed by
Greg Kroah-Hartman
022f7b07 68f5f996

+16 -8
+16 -8
drivers/base/power/sysfs.c
··· 27 27 28 28 static ssize_t state_show(struct device * dev, struct device_attribute *attr, char * buf) 29 29 { 30 - return sprintf(buf, "%u\n", dev->power.power_state.event); 30 + if (dev->power.power_state.event) 31 + return sprintf(buf, "2\n"); 32 + else 33 + return sprintf(buf, "0\n"); 31 34 } 32 35 33 36 static ssize_t state_store(struct device * dev, struct device_attribute *attr, const char * buf, size_t n) 34 37 { 35 38 pm_message_t state; 36 - char * rest; 37 - int error = 0; 39 + int error = -EINVAL; 38 40 39 - state.event = simple_strtoul(buf, &rest, 10); 40 - if (*rest) 41 - return -EINVAL; 42 - if (state.event) 41 + state.event = PM_EVENT_SUSPEND; 42 + /* Older apps expected to write "3" here - confused with PCI D3 */ 43 + if ((n == 1) && !strcmp(buf, "3")) 43 44 error = dpm_runtime_suspend(dev, state); 44 - else 45 + 46 + if ((n == 1) && !strcmp(buf, "2")) 47 + error = dpm_runtime_suspend(dev, state); 48 + 49 + if ((n == 1) && !strcmp(buf, "0")) { 45 50 dpm_runtime_resume(dev); 51 + error = 0; 52 + } 53 + 46 54 return error ? error : n; 47 55 } 48 56