summaryrefslogtreecommitdiffstats
path: root/drivers/platform/x86/thinkpad_acpi.c
diff options
context:
space:
mode:
authorAdam Lee <adam.lee@canonical.com>2013-06-08 16:51:15 +0800
committerMatthew Garrett <matthew.garrett@nebula.com>2013-09-05 08:51:13 -0400
commitedf2d7780da5d96a168da7e31b36fb11620106d3 (patch)
treef96a474335640bc8a71bf4d74ddbdd36bbe994cd /drivers/platform/x86/thinkpad_acpi.c
parentcb3e4330e697dffaf3d9cefebc9c7e7d39c89f2e (diff)
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: Adam Lee <adam.lee@canonical.com> Acked-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br> Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
Diffstat (limited to 'drivers/platform/x86/thinkpad_acpi.c')
-rw-r--r--drivers/platform/x86/thinkpad_acpi.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index be67e5e28d1..359c87b3b1b 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -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")) {