aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video/backlight
diff options
context:
space:
mode:
authorRichard Purdie <rpurdie@rpsys.net>2006-05-15 12:44:15 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-05-15 14:20:56 -0400
commit68673afd443c5eeb4cebfb9026e3675f43d79f2b (patch)
treeb8350ec63cee168284b35016aa097334c215d633 /drivers/video/backlight
parenta8d2e7d95229db9999682113bfac40b49978f212 (diff)
[PATCH] Backlight/LCD Class: Fix sysfs _store error handling
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>
Diffstat (limited to 'drivers/video/backlight')
-rw-r--r--drivers/video/backlight/backlight.c18
-rw-r--r--drivers/video/backlight/lcd.c32
2 files changed, 28 insertions, 22 deletions
diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index 334b1db1bd7c..27597c576eff 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -29,12 +29,15 @@ static ssize_t backlight_show_power(struct class_device *cdev, char *buf)
29 29
30static ssize_t backlight_store_power(struct class_device *cdev, const char *buf, size_t count) 30static ssize_t backlight_store_power(struct class_device *cdev, const char *buf, size_t count)
31{ 31{
32 int rc = -ENXIO, power; 32 int rc = -ENXIO;
33 char *endp; 33 char *endp;
34 struct backlight_device *bd = to_backlight_device(cdev); 34 struct backlight_device *bd = to_backlight_device(cdev);
35 int power = simple_strtoul(buf, &endp, 0);
36 size_t size = endp - buf;
35 37
36 power = simple_strtoul(buf, &endp, 0); 38 if (*endp && isspace(*endp))
37 if (*endp && !isspace(*endp)) 39 size++;
40 if (size != count)
38 return -EINVAL; 41 return -EINVAL;
39 42
40 down(&bd->sem); 43 down(&bd->sem);
@@ -65,12 +68,15 @@ static ssize_t backlight_show_brightness(struct class_device *cdev, char *buf)
65 68
66static ssize_t backlight_store_brightness(struct class_device *cdev, const char *buf, size_t count) 69static ssize_t backlight_store_brightness(struct class_device *cdev, const char *buf, size_t count)
67{ 70{
68 int rc = -ENXIO, brightness; 71 int rc = -ENXIO;
69 char *endp; 72 char *endp;
70 struct backlight_device *bd = to_backlight_device(cdev); 73 struct backlight_device *bd = to_backlight_device(cdev);
74 int brightness = simple_strtoul(buf, &endp, 0);
75 size_t size = endp - buf;
71 76
72 brightness = simple_strtoul(buf, &endp, 0); 77 if (*endp && isspace(*endp))
73 if (*endp && !isspace(*endp)) 78 size++;
79 if (size != count)
74 return -EINVAL; 80 return -EINVAL;
75 81
76 down(&bd->sem); 82 down(&bd->sem);
diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c
index 86908a60c630..bc8ab005a3fb 100644
--- a/drivers/video/backlight/lcd.c
+++ b/drivers/video/backlight/lcd.c
@@ -31,12 +31,15 @@ static ssize_t lcd_show_power(struct class_device *cdev, char *buf)
31 31
32static ssize_t lcd_store_power(struct class_device *cdev, const char *buf, size_t count) 32static ssize_t lcd_store_power(struct class_device *cdev, const char *buf, size_t count)
33{ 33{
34 int rc, power; 34 int rc = -ENXIO;
35 char *endp; 35 char *endp;
36 struct lcd_device *ld = to_lcd_device(cdev); 36 struct lcd_device *ld = to_lcd_device(cdev);
37 int power = simple_strtoul(buf, &endp, 0);
38 size_t size = endp - buf;
37 39
38 power = simple_strtoul(buf, &endp, 0); 40 if (*endp && isspace(*endp))
39 if (*endp && !isspace(*endp)) 41 size++;
42 if (size != count)
40 return -EINVAL; 43 return -EINVAL;
41 44
42 down(&ld->sem); 45 down(&ld->sem);
@@ -44,8 +47,7 @@ static ssize_t lcd_store_power(struct class_device *cdev, const char *buf, size_
44 pr_debug("lcd: set power to %d\n", power); 47 pr_debug("lcd: set power to %d\n", power);
45 ld->props->set_power(ld, power); 48 ld->props->set_power(ld, power);
46 rc = count; 49 rc = count;
47 } else 50 }
48 rc = -ENXIO;
49 up(&ld->sem); 51 up(&ld->sem);
50 52
51 return rc; 53 return rc;
@@ -53,14 +55,12 @@ static ssize_t lcd_store_power(struct class_device *cdev, const char *buf, size_
53 55
54static ssize_t lcd_show_contrast(struct class_device *cdev, char *buf) 56static ssize_t lcd_show_contrast(struct class_device *cdev, char *buf)
55{ 57{
56 int rc; 58 int rc = -ENXIO;
57 struct lcd_device *ld = to_lcd_device(cdev); 59 struct lcd_device *ld = to_lcd_device(cdev);
58 60
59 down(&ld->sem); 61 down(&ld->sem);
60 if (likely(ld->props && ld->props->get_contrast)) 62 if (likely(ld->props && ld->props->get_contrast))
61 rc = sprintf(buf, "%d\n", ld->props->get_contrast(ld)); 63 rc = sprintf(buf, "%d\n", ld->props->get_contrast(ld));
62 else
63 rc = -ENXIO;
64 up(&ld->sem); 64 up(&ld->sem);
65 65
66 return rc; 66 return rc;
@@ -68,12 +68,15 @@ static ssize_t lcd_show_contrast(struct class_device *cdev, char *buf)
68 68
69static ssize_t lcd_store_contrast(struct class_device *cdev, const char *buf, size_t count) 69static ssize_t lcd_store_contrast(struct class_device *cdev, const char *buf, size_t count)
70{ 70{
71 int rc, contrast; 71 int rc = -ENXIO;
72 char *endp; 72 char *endp;
73 struct lcd_device *ld = to_lcd_device(cdev); 73 struct lcd_device *ld = to_lcd_device(cdev);
74 int contrast = simple_strtoul(buf, &endp, 0);
75 size_t size = endp - buf;
74 76
75 contrast = simple_strtoul(buf, &endp, 0); 77 if (*endp && isspace(*endp))
76 if (*endp && !isspace(*endp)) 78 size++;
79 if (size != count)
77 return -EINVAL; 80 return -EINVAL;
78 81
79 down(&ld->sem); 82 down(&ld->sem);
@@ -81,8 +84,7 @@ static ssize_t lcd_store_contrast(struct class_device *cdev, const char *buf, si
81 pr_debug("lcd: set contrast to %d\n", contrast); 84 pr_debug("lcd: set contrast to %d\n", contrast);
82 ld->props->set_contrast(ld, contrast); 85 ld->props->set_contrast(ld, contrast);
83 rc = count; 86 rc = count;
84 } else 87 }
85 rc = -ENXIO;
86 up(&ld->sem); 88 up(&ld->sem);
87 89
88 return rc; 90 return rc;
@@ -90,14 +92,12 @@ static ssize_t lcd_store_contrast(struct class_device *cdev, const char *buf, si
90 92
91static ssize_t lcd_show_max_contrast(struct class_device *cdev, char *buf) 93static ssize_t lcd_show_max_contrast(struct class_device *cdev, char *buf)
92{ 94{
93 int rc; 95 int rc = -ENXIO;
94 struct lcd_device *ld = to_lcd_device(cdev); 96 struct lcd_device *ld = to_lcd_device(cdev);
95 97
96 down(&ld->sem); 98 down(&ld->sem);
97 if (likely(ld->props)) 99 if (likely(ld->props))
98 rc = sprintf(buf, "%d\n", ld->props->max_contrast); 100 rc = sprintf(buf, "%d\n", ld->props->max_contrast);
99 else
100 rc = -ENXIO;
101 up(&ld->sem); 101 up(&ld->sem);
102 102
103 return rc; 103 return rc;