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>
This commit is contained in:
Pavel Machek
2008-12-03 08:43:48 +00:00
committed by Richard Purdie
parent 866bbdba77
commit 9a2c61a921

View File

@@ -80,20 +80,18 @@ static ssize_t backlight_show_power(struct device *dev,
static ssize_t backlight_store_power(struct device *dev, static ssize_t backlight_store_power(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count) struct device_attribute *attr, const char *buf, size_t count)
{ {
int rc = -ENXIO; int rc;
char *endp;
struct backlight_device *bd = to_backlight_device(dev); struct backlight_device *bd = to_backlight_device(dev);
int power = simple_strtoul(buf, &endp, 0); unsigned long power;
size_t size = endp - buf;
if (*endp && isspace(*endp)) rc = strict_strtoul(buf, 0, &power);
size++; if (rc)
if (size != count) return rc;
return -EINVAL;
rc = -ENXIO;
mutex_lock(&bd->ops_lock); mutex_lock(&bd->ops_lock);
if (bd->ops) { if (bd->ops) {
pr_debug("backlight: set power to %d\n", power); pr_debug("backlight: set power to %lu\n", power);
if (bd->props.power != power) { if (bd->props.power != power) {
bd->props.power = power; bd->props.power = power;
backlight_update_status(bd); backlight_update_status(bd);
@@ -116,23 +114,22 @@ static ssize_t backlight_show_brightness(struct device *dev,
static ssize_t backlight_store_brightness(struct device *dev, static ssize_t backlight_store_brightness(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count) struct device_attribute *attr, const char *buf, size_t count)
{ {
int rc = -ENXIO; int rc;
char *endp;
struct backlight_device *bd = to_backlight_device(dev); struct backlight_device *bd = to_backlight_device(dev);
int brightness = simple_strtoul(buf, &endp, 0); unsigned long brightness;
size_t size = endp - buf;
if (*endp && isspace(*endp)) rc = strict_strtoul(buf, 0, &brightness);
size++; if (rc)
if (size != count) return rc;
return -EINVAL;
rc = -ENXIO;
mutex_lock(&bd->ops_lock); mutex_lock(&bd->ops_lock);
if (bd->ops) { if (bd->ops) {
if (brightness > bd->props.max_brightness) if (brightness > bd->props.max_brightness)
rc = -EINVAL; rc = -EINVAL;
else { else {
pr_debug("backlight: set brightness to %d\n", pr_debug("backlight: set brightness to %lu\n",
brightness); brightness);
if (bd->props.brightness != brightness) { if (bd->props.brightness != brightness) {
bd->props.brightness = brightness; bd->props.brightness = brightness;