Commit 3dc7b82e authored by Richard Purdie's avatar Richard Purdie Committed by Linus Torvalds

[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: default avatarRichard Purdie <rpurdie@rpsys.net>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 263de9b5
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/sysdev.h> #include <linux/sysdev.h>
#include <linux/timer.h> #include <linux/timer.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/ctype.h>
#include <linux/leds.h> #include <linux/leds.h>
#include "leds.h" #include "leds.h"
...@@ -43,9 +44,13 @@ static ssize_t led_brightness_store(struct class_device *dev, ...@@ -43,9 +44,13 @@ static ssize_t led_brightness_store(struct class_device *dev,
ssize_t ret = -EINVAL; ssize_t ret = -EINVAL;
char *after; char *after;
unsigned long state = simple_strtoul(buf, &after, 10); unsigned long state = simple_strtoul(buf, &after, 10);
size_t count = after - buf;
if (after - buf > 0) { if (*after && isspace(*after))
ret = after - buf; count++;
if (count == size) {
ret = count;
led_set_brightness(led_cdev, state); led_set_brightness(led_cdev, state);
} }
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/sysdev.h> #include <linux/sysdev.h>
#include <linux/timer.h> #include <linux/timer.h>
#include <linux/ctype.h>
#include <linux/leds.h> #include <linux/leds.h>
#include "leds.h" #include "leds.h"
...@@ -69,11 +70,15 @@ static ssize_t led_delay_on_store(struct class_device *dev, const char *buf, ...@@ -69,11 +70,15 @@ static ssize_t led_delay_on_store(struct class_device *dev, const char *buf,
int ret = -EINVAL; int ret = -EINVAL;
char *after; char *after;
unsigned long state = simple_strtoul(buf, &after, 10); unsigned long state = simple_strtoul(buf, &after, 10);
size_t count = after - buf;
if (after - buf > 0) { if (*after && isspace(*after))
count++;
if (count == size) {
timer_data->delay_on = state; timer_data->delay_on = state;
mod_timer(&timer_data->timer, jiffies + 1); mod_timer(&timer_data->timer, jiffies + 1);
ret = after - buf; ret = count;
} }
return ret; return ret;
...@@ -97,11 +102,15 @@ static ssize_t led_delay_off_store(struct class_device *dev, const char *buf, ...@@ -97,11 +102,15 @@ static ssize_t led_delay_off_store(struct class_device *dev, const char *buf,
int ret = -EINVAL; int ret = -EINVAL;
char *after; char *after;
unsigned long state = simple_strtoul(buf, &after, 10); unsigned long state = simple_strtoul(buf, &after, 10);
size_t count = after - buf;
if (*after && isspace(*after))
count++;
if (after - buf > 0) { if (count == size) {
timer_data->delay_off = state; timer_data->delay_off = state;
mod_timer(&timer_data->timer, jiffies + 1); mod_timer(&timer_data->timer, jiffies + 1);
ret = after - buf; ret = count;
} }
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment