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

drivers/leds/ledtrig-gpio.c: make output match input, tighten input checking

Replicate changes made to drivers/leds/ledtrig-backlight.c.

Cc: Paul Mundt <lethal@linux-sh.org>
Cc: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Janusz Krzysztofik and committed by
Linus Torvalds
cc587ece c1fc8675

+9 -8
+9 -8
drivers/leds/ledtrig-gpio.c
··· 99 99 struct led_classdev *led = dev_get_drvdata(dev); 100 100 struct gpio_trig_data *gpio_data = led->trigger_data; 101 101 102 - return sprintf(buf, "%s\n", gpio_data->inverted ? "yes" : "no"); 102 + return sprintf(buf, "%u\n", gpio_data->inverted); 103 103 } 104 104 105 105 static ssize_t gpio_trig_inverted_store(struct device *dev, ··· 107 107 { 108 108 struct led_classdev *led = dev_get_drvdata(dev); 109 109 struct gpio_trig_data *gpio_data = led->trigger_data; 110 - unsigned inverted; 110 + unsigned long inverted; 111 111 int ret; 112 112 113 - ret = sscanf(buf, "%u", &inverted); 114 - if (ret < 1) { 115 - dev_err(dev, "invalid value\n"); 116 - return -EINVAL; 117 - } 113 + ret = strict_strtoul(buf, 10, &inverted); 114 + if (ret < 0) 115 + return ret; 118 116 119 - gpio_data->inverted = !!inverted; 117 + if (inverted > 1) 118 + return -EINVAL; 119 + 120 + gpio_data->inverted = inverted; 120 121 121 122 /* After inverting, we need to update the LED. */ 122 123 schedule_work(&gpio_data->work);