Commit 3dc7b82ea7649356bf027fba50c16ca50cec31e2

Authored by Richard Purdie
Committed by Linus Torvalds
1 parent 263de9b582

[PATCH] LED: Fix sysfs store function error handling

Fix the error handling of some LED _store functions.  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>

Showing 2 changed files with 20 additions and 6 deletions Side-by-side Diff

drivers/leds/led-class.c
... ... @@ -19,6 +19,7 @@
19 19 #include <linux/sysdev.h>
20 20 #include <linux/timer.h>
21 21 #include <linux/err.h>
  22 +#include <linux/ctype.h>
22 23 #include <linux/leds.h>
23 24 #include "leds.h"
24 25  
25 26  
... ... @@ -43,9 +44,13 @@
43 44 ssize_t ret = -EINVAL;
44 45 char *after;
45 46 unsigned long state = simple_strtoul(buf, &after, 10);
  47 + size_t count = after - buf;
46 48  
47   - if (after - buf > 0) {
48   - ret = after - buf;
  49 + if (*after && isspace(*after))
  50 + count++;
  51 +
  52 + if (count == size) {
  53 + ret = count;
49 54 led_set_brightness(led_cdev, state);
50 55 }
51 56  
drivers/leds/ledtrig-timer.c
... ... @@ -20,6 +20,7 @@
20 20 #include <linux/device.h>
21 21 #include <linux/sysdev.h>
22 22 #include <linux/timer.h>
  23 +#include <linux/ctype.h>
23 24 #include <linux/leds.h>
24 25 #include "leds.h"
25 26  
26 27  
27 28  
... ... @@ -69,11 +70,15 @@
69 70 int ret = -EINVAL;
70 71 char *after;
71 72 unsigned long state = simple_strtoul(buf, &after, 10);
  73 + size_t count = after - buf;
72 74  
73   - if (after - buf > 0) {
  75 + if (*after && isspace(*after))
  76 + count++;
  77 +
  78 + if (count == size) {
74 79 timer_data->delay_on = state;
75 80 mod_timer(&timer_data->timer, jiffies + 1);
76   - ret = after - buf;
  81 + ret = count;
77 82 }
78 83  
79 84 return ret;
80 85  
81 86  
... ... @@ -97,11 +102,15 @@
97 102 int ret = -EINVAL;
98 103 char *after;
99 104 unsigned long state = simple_strtoul(buf, &after, 10);
  105 + size_t count = after - buf;
100 106  
101   - if (after - buf > 0) {
  107 + if (*after && isspace(*after))
  108 + count++;
  109 +
  110 + if (count == size) {
102 111 timer_data->delay_off = state;
103 112 mod_timer(&timer_data->timer, jiffies + 1);
104   - ret = after - buf;
  113 + ret = count;
105 114 }
106 115  
107 116 return ret;