Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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>

authored by

Richard Purdie and committed by
Linus Torvalds
3dc7b82e 263de9b5

+20 -6
+7 -2
drivers/leds/led-class.c
··· 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 ··· 44 43 ssize_t ret = -EINVAL; 45 44 char *after; 46 45 unsigned long state = simple_strtoul(buf, &after, 10); 46 + size_t count = after - buf; 47 47 48 - if (after - buf > 0) { 49 - ret = after - buf; 48 + if (*after && isspace(*after)) 49 + count++; 50 + 51 + if (count == size) { 52 + ret = count; 50 53 led_set_brightness(led_cdev, state); 51 54 } 52 55
+13 -4
drivers/leds/ledtrig-timer.c
··· 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 ··· 70 69 int ret = -EINVAL; 71 70 char *after; 72 71 unsigned long state = simple_strtoul(buf, &after, 10); 72 + size_t count = after - buf; 73 73 74 - if (after - buf > 0) { 74 + if (*after && isspace(*after)) 75 + count++; 76 + 77 + if (count == size) { 75 78 timer_data->delay_on = state; 76 79 mod_timer(&timer_data->timer, jiffies + 1); 77 - ret = after - buf; 80 + ret = count; 78 81 } 79 82 80 83 return ret; ··· 102 97 int ret = -EINVAL; 103 98 char *after; 104 99 unsigned long state = simple_strtoul(buf, &after, 10); 100 + size_t count = after - buf; 105 101 106 - if (after - buf > 0) { 102 + if (*after && isspace(*after)) 103 + count++; 104 + 105 + if (count == size) { 107 106 timer_data->delay_off = state; 108 107 mod_timer(&timer_data->timer, jiffies + 1); 109 - ret = after - buf; 108 + ret = count; 110 109 } 111 110 112 111 return ret;