diff options
author | Pavel Machek <pavel@suse.cz> | 2008-12-03 03:43:48 -0500 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2009-01-08 07:37:28 -0500 |
commit | 9a2c61a921a8aeabacaccad0d2fdf75e1c1475fb (patch) | |
tree | 46aceedf2a75a9025422b7c159e54704e47767db /drivers/video | |
parent | 866bbdba7795cac2da24853ea2259e0e4ef7d02d (diff) |
backlight: Catch invalid input in sysfs attributes
Check input properly in backlight, echo > brightness should not turn off
the backlight.
[akpm@linux-foundation.org: coding-style fixes]
[akpm@linux-foundation.org: fix printk warning]
Signed-off-by: Pavel Machek <pavel@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'drivers/video')
-rw-r--r-- | drivers/video/backlight/backlight.c | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c index 0664fc032235..9593fdc042f7 100644 --- a/drivers/video/backlight/backlight.c +++ b/drivers/video/backlight/backlight.c | |||
@@ -80,20 +80,18 @@ static ssize_t backlight_show_power(struct device *dev, | |||
80 | static ssize_t backlight_store_power(struct device *dev, | 80 | static ssize_t backlight_store_power(struct device *dev, |
81 | struct device_attribute *attr, const char *buf, size_t count) | 81 | struct device_attribute *attr, const char *buf, size_t count) |
82 | { | 82 | { |
83 | int rc = -ENXIO; | 83 | int rc; |
84 | char *endp; | ||
85 | struct backlight_device *bd = to_backlight_device(dev); | 84 | struct backlight_device *bd = to_backlight_device(dev); |
86 | int power = simple_strtoul(buf, &endp, 0); | 85 | unsigned long power; |
87 | size_t size = endp - buf; | ||
88 | 86 | ||
89 | if (*endp && isspace(*endp)) | 87 | rc = strict_strtoul(buf, 0, &power); |
90 | size++; | 88 | if (rc) |
91 | if (size != count) | 89 | return rc; |
92 | return -EINVAL; | ||
93 | 90 | ||
91 | rc = -ENXIO; | ||
94 | mutex_lock(&bd->ops_lock); | 92 | mutex_lock(&bd->ops_lock); |
95 | if (bd->ops) { | 93 | if (bd->ops) { |
96 | pr_debug("backlight: set power to %d\n", power); | 94 | pr_debug("backlight: set power to %lu\n", power); |
97 | if (bd->props.power != power) { | 95 | if (bd->props.power != power) { |
98 | bd->props.power = power; | 96 | bd->props.power = power; |
99 | backlight_update_status(bd); | 97 | backlight_update_status(bd); |
@@ -116,23 +114,22 @@ static ssize_t backlight_show_brightness(struct device *dev, | |||
116 | static ssize_t backlight_store_brightness(struct device *dev, | 114 | static ssize_t backlight_store_brightness(struct device *dev, |
117 | struct device_attribute *attr, const char *buf, size_t count) | 115 | struct device_attribute *attr, const char *buf, size_t count) |
118 | { | 116 | { |
119 | int rc = -ENXIO; | 117 | int rc; |
120 | char *endp; | ||
121 | struct backlight_device *bd = to_backlight_device(dev); | 118 | struct backlight_device *bd = to_backlight_device(dev); |
122 | int brightness = simple_strtoul(buf, &endp, 0); | 119 | unsigned long brightness; |
123 | size_t size = endp - buf; | 120 | |
121 | rc = strict_strtoul(buf, 0, &brightness); | ||
122 | if (rc) | ||
123 | return rc; | ||
124 | 124 | ||
125 | if (*endp && isspace(*endp)) | 125 | rc = -ENXIO; |
126 | size++; | ||
127 | if (size != count) | ||
128 | return -EINVAL; | ||
129 | 126 | ||
130 | mutex_lock(&bd->ops_lock); | 127 | mutex_lock(&bd->ops_lock); |
131 | if (bd->ops) { | 128 | if (bd->ops) { |
132 | if (brightness > bd->props.max_brightness) | 129 | if (brightness > bd->props.max_brightness) |
133 | rc = -EINVAL; | 130 | rc = -EINVAL; |
134 | else { | 131 | else { |
135 | pr_debug("backlight: set brightness to %d\n", | 132 | pr_debug("backlight: set brightness to %lu\n", |
136 | brightness); | 133 | brightness); |
137 | if (bd->props.brightness != brightness) { | 134 | if (bd->props.brightness != brightness) { |
138 | bd->props.brightness = brightness; | 135 | bd->props.brightness = brightness; |