[PATCH] input: gpio-keys: report error when invalid key number

From: Peng Fan
Date: Mon Aug 24 2015 - 08:07:50 EST

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
root@yocto:/sys/devices/soc0/gpio-keys# echo 77 > 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 <van.freenix@xxxxxxxxx>
Cc: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
Cc: Linus Walleij <linus.walleij@xxxxxxxxxx>
Cc: Alexander Stein <alexander.stein@xxxxxxxxxxxxxxxxxxxxx>
Cc: Tejun Heo <tj@xxxxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: Wolfram Sang <wsa@xxxxxxxxxxxxx>
Cc: Fabio Estevam <fabio.estevam@xxxxxxxxxxxxx>
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;
+ }

for (i = 0; i < ddata->pdata->nbuttons; i++) {

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/