Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754167AbbHXMHr (ORCPT ); Mon, 24 Aug 2015 08:07:47 -0400 Received: from mail-pd0-f182.google.com ([209.85.192.182]:36408 "EHLO mail-pd0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751834AbbHXMHq (ORCPT ); Mon, 24 Aug 2015 08:07:46 -0400 From: Peng Fan To: dmitry.torokhov@gmail.com Cc: linus.walleij@linaro.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, van.freenix@gmail.com, Alexander Stein , Tejun Heo , Andrew Morton , Wolfram Sang , Fabio Estevam Subject: [PATCH] input: gpio-keys: report error when invalid key number Date: Mon, 24 Aug 2015 20:07:44 +0800 Message-Id: <1440418064-15971-1-git-send-email-van.freenix@gmail.com> X-Mailer: git-send-email 1.8.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1586 Lines: 49 When the input key number is not valid one of '/sys/devices/soc0/gpio-keys/keys', need to report an error, but not continue. See the following example: root@yocto:/sys/devices/soc0/gpio-keys# cat keys 114-116 root@yocto:/sys/devices/soc0/gpio-keys# echo 77 > keys root@yocto:/sys/devices/soc0/gpio-keys# we want 'echo 77 > keys' to report an error, but not silence to give us an fake illusion that all is 'ok'. Signed-off-by: Peng Fan Cc: Dmitry Torokhov Cc: Linus Walleij Cc: Alexander Stein Cc: Tejun Heo Cc: Andrew Morton Cc: Wolfram Sang Cc: Fabio Estevam --- drivers/input/keyboard/gpio_keys.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index ddf4045..b98f3b4 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -239,6 +239,11 @@ static ssize_t gpio_keys_attr_store_helper(struct gpio_keys_drvdata *ddata, } } + if (i == ddata->pdata->nbuttons) { + error = -EINVAL; + goto out; + } + mutex_lock(&ddata->disable_lock); for (i = 0; i < ddata->pdata->nbuttons; i++) { -- 1.8.4.5 -- 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/