Commit 022f7b07 authored by Pavel Machek's avatar Pavel Machek Committed by Greg Kroah-Hartman

[PATCH] Fix Userspace interface breakage in power/state

Prevent passing invalid values down to the drivers.
Signed-off-by: default avatarPavel Machek <pavel@suse.cz>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 68f5f996
...@@ -27,22 +27,30 @@ ...@@ -27,22 +27,30 @@
static ssize_t state_show(struct device * dev, struct device_attribute *attr, char * buf) static ssize_t state_show(struct device * dev, struct device_attribute *attr, char * buf)
{ {
return sprintf(buf, "%u\n", dev->power.power_state.event); if (dev->power.power_state.event)
return sprintf(buf, "2\n");
else
return sprintf(buf, "0\n");
} }
static ssize_t state_store(struct device * dev, struct device_attribute *attr, const char * buf, size_t n) static ssize_t state_store(struct device * dev, struct device_attribute *attr, const char * buf, size_t n)
{ {
pm_message_t state; pm_message_t state;
char * rest; int error = -EINVAL;
int error = 0;
state.event = simple_strtoul(buf, &rest, 10); state.event = PM_EVENT_SUSPEND;
if (*rest) /* Older apps expected to write "3" here - confused with PCI D3 */
return -EINVAL; if ((n == 1) && !strcmp(buf, "3"))
if (state.event)
error = dpm_runtime_suspend(dev, state); error = dpm_runtime_suspend(dev, state);
else
if ((n == 1) && !strcmp(buf, "2"))
error = dpm_runtime_suspend(dev, state);
if ((n == 1) && !strcmp(buf, "0")) {
dpm_runtime_resume(dev); dpm_runtime_resume(dev);
error = 0;
}
return error ? error : n; return error ? error : n;
} }
......
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