Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754458Ab3FGJHs (ORCPT ); Fri, 7 Jun 2013 05:07:48 -0400 Received: from mail-pd0-f177.google.com ([209.85.192.177]:56965 "EHLO mail-pd0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754241Ab3FGJHo (ORCPT ); Fri, 7 Jun 2013 05:07:44 -0400 From: Adam Lee To: linux-kernel@vger.kernel.org Cc: platform-driver-x86@vger.kernel.org, ibm-acpi-devel@lists.sourceforge.net, Matthew Garrett , Henrique de Moraes Holschuh , Alex Hung , Bjorn Mork Subject: [PATCH v2] thinkpad_acpi: return -NODEV while operating uninitialized LEDs Date: Fri, 7 Jun 2013 17:05:32 +0800 Message-Id: <1370595932-29889-1-git-send-email-adam.lee@canonical.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1370593209-21358-1-git-send-email-adam.lee@canonical.com> References: <1370593209-21358-1-git-send-email-adam.lee@canonical.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1171 Lines: 34 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 --- drivers/platform/x86/thinkpad_acpi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index 54d31c0..d2ac4e8 100644 --- a/drivers/platform/x86/thinkpad_acpi.c +++ b/drivers/platform/x86/thinkpad_acpi.c @@ -5401,9 +5401,12 @@ 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 || led < 0 || led > (TPACPI_LED_NUMLEDS -1)) return -EINVAL; + if (!tpacpi_leds[led].led) + return -ENODEV; + if (strstr(cmd, "off")) { s = TPACPI_LED_OFF; } else if (strstr(cmd, "on")) { -- 1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/