]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
[PATCH] Backlight/LCD Class: Fix sysfs _store error handling
authorRichard Purdie <rpurdie@rpsys.net>
Mon, 15 May 2006 16:44:15 +0000 (09:44 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Mon, 15 May 2006 18:20:56 +0000 (11:20 -0700)
The backlight and LCD class _store functions currently accept values like "34
some random strings" without error.  This corrects them to return -EINVAL if
the value is not numeric with an optional byte of trailing whitespace.

Signed-off-by: Richard Purdie <rpurdie@rpsys.net>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
drivers/video/backlight/backlight.c
drivers/video/backlight/lcd.c

index 334b1db1bd7cc42f52e3a5c3353dd28b7b1c032d..27597c576eff3f4cb0a116dee1d682f8ce4f9383 100644 (file)
@@ -29,12 +29,15 @@ static ssize_t backlight_show_power(struct class_device *cdev, char *buf)
 
 static ssize_t backlight_store_power(struct class_device *cdev, const char *buf, size_t count)
 {
-       int rc = -ENXIO, power;
+       int rc = -ENXIO;
        char *endp;
        struct backlight_device *bd = to_backlight_device(cdev);
+       int power = simple_strtoul(buf, &endp, 0);
+       size_t size = endp - buf;
 
-       power = simple_strtoul(buf, &endp, 0);
-       if (*endp && !isspace(*endp))
+       if (*endp && isspace(*endp))
+               size++;
+       if (size != count)
                return -EINVAL;
 
        down(&bd->sem);
@@ -65,12 +68,15 @@ static ssize_t backlight_show_brightness(struct class_device *cdev, char *buf)
 
 static ssize_t backlight_store_brightness(struct class_device *cdev, const char *buf, size_t count)
 {
-       int rc = -ENXIO, brightness;
+       int rc = -ENXIO;
        char *endp;
        struct backlight_device *bd = to_backlight_device(cdev);
+       int brightness = simple_strtoul(buf, &endp, 0);
+       size_t size = endp - buf;
 
-       brightness = simple_strtoul(buf, &endp, 0);
-       if (*endp && !isspace(*endp))
+       if (*endp && isspace(*endp))
+               size++;
+       if (size != count)
                return -EINVAL;
 
        down(&bd->sem);
index 86908a60c630d9624fab519c24d1ab0f28091e3b..bc8ab005a3fb174a9eecc050a76301469ed2916f 100644 (file)
@@ -31,12 +31,15 @@ static ssize_t lcd_show_power(struct class_device *cdev, char *buf)
 
 static ssize_t lcd_store_power(struct class_device *cdev, const char *buf, size_t count)
 {
-       int rc, power;
+       int rc = -ENXIO;
        char *endp;
        struct lcd_device *ld = to_lcd_device(cdev);
+       int power = simple_strtoul(buf, &endp, 0);
+       size_t size = endp - buf;
 
-       power = simple_strtoul(buf, &endp, 0);
-       if (*endp && !isspace(*endp))
+       if (*endp && isspace(*endp))
+               size++;
+       if (size != count)
                return -EINVAL;
 
        down(&ld->sem);
@@ -44,8 +47,7 @@ static ssize_t lcd_store_power(struct class_device *cdev, const char *buf, size_
                pr_debug("lcd: set power to %d\n", power);
                ld->props->set_power(ld, power);
                rc = count;
-       } else
-               rc = -ENXIO;
+       }
        up(&ld->sem);
 
        return rc;
@@ -53,14 +55,12 @@ static ssize_t lcd_store_power(struct class_device *cdev, const char *buf, size_
 
 static ssize_t lcd_show_contrast(struct class_device *cdev, char *buf)
 {
-       int rc;
+       int rc = -ENXIO;
        struct lcd_device *ld = to_lcd_device(cdev);
 
        down(&ld->sem);
        if (likely(ld->props && ld->props->get_contrast))
                rc = sprintf(buf, "%d\n", ld->props->get_contrast(ld));
-       else
-               rc = -ENXIO;
        up(&ld->sem);
 
        return rc;
@@ -68,12 +68,15 @@ static ssize_t lcd_show_contrast(struct class_device *cdev, char *buf)
 
 static ssize_t lcd_store_contrast(struct class_device *cdev, const char *buf, size_t count)
 {
-       int rc, contrast;
+       int rc = -ENXIO;
        char *endp;
        struct lcd_device *ld = to_lcd_device(cdev);
+       int contrast = simple_strtoul(buf, &endp, 0);
+       size_t size = endp - buf;
 
-       contrast = simple_strtoul(buf, &endp, 0);
-       if (*endp && !isspace(*endp))
+       if (*endp && isspace(*endp))
+               size++;
+       if (size != count)
                return -EINVAL;
 
        down(&ld->sem);
@@ -81,8 +84,7 @@ static ssize_t lcd_store_contrast(struct class_device *cdev, const char *buf, si
                pr_debug("lcd: set contrast to %d\n", contrast);
                ld->props->set_contrast(ld, contrast);
                rc = count;
-       } else
-               rc = -ENXIO;
+       }
        up(&ld->sem);
 
        return rc;
@@ -90,14 +92,12 @@ static ssize_t lcd_store_contrast(struct class_device *cdev, const char *buf, si
 
 static ssize_t lcd_show_max_contrast(struct class_device *cdev, char *buf)
 {
-       int rc;
+       int rc = -ENXIO;
        struct lcd_device *ld = to_lcd_device(cdev);
 
        down(&ld->sem);
        if (likely(ld->props))
                rc = sprintf(buf, "%d\n", ld->props->max_contrast);
-       else
-               rc = -ENXIO;
        up(&ld->sem);
 
        return rc;