Commit edf2d778 authored by Adam Lee's avatar Adam Lee Committed by Matthew Garrett

thinkpad_acpi: return -NODEV while operating uninitialized LEDs

Not all 0-15 LEDs are available for all models, sometimes it's even not
safe. This patch return -NODEV while operating uninitialized LEDs.
Signed-off-by: default avatarAdam Lee <adam.lee@canonical.com>
Acked-by: default avatarHenrique de Moraes Holschuh <hmh@hmh.eng.br>
Signed-off-by: default avatarMatthew Garrett <matthew.garrett@nebula.com>
parent cb3e4330
......@@ -369,7 +369,7 @@ struct tpacpi_led_classdev {
struct led_classdev led_classdev;
struct work_struct work;
enum led_status_t new_state;
unsigned int led;
int led;
};
/* brightness level capabilities */
......@@ -5313,6 +5313,8 @@ static int __init led_init(struct ibm_init_struct *iibm)
ARRAY_SIZE(led_useful_qtable));
for (i = 0; i < TPACPI_LED_NUMLEDS; i++) {
tpacpi_leds[i].led = -1;
if (!tpacpi_is_led_restricted(i) &&
test_bit(i, &useful_leds)) {
rc = tpacpi_init_led(i);
......@@ -5370,9 +5372,13 @@ static int led_write(char *buf)
return -ENODEV;
while ((cmd = next_cmd(&buf))) {
if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 15)
if (sscanf(cmd, "%d", &led) != 1)
return -EINVAL;
if (led < 0 || led > (TPACPI_LED_NUMLEDS - 1) ||
tpacpi_leds[led].led < 0)
return -ENODEV;
if (strstr(cmd, "off")) {
s = TPACPI_LED_OFF;
} else if (strstr(cmd, "on")) {
......
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