Input: gpio-keys - report error when disabling unsupported key
authorPeng Fan <van.freenix@gmail.com>
Mon, 24 Aug 2015 17:42:25 +0000 (10:42 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Mon, 24 Aug 2015 17:55:48 +0000 (10:55 -0700)
When trying to disable a key that is not supported by the device we should
report error, not do nothing and report success:

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 silence to give us an
illusion that all is 'ok'.

Signed-off-by: Peng Fan <van.freenix@gmail.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/keyboard/gpio_keys.c

index 1df4507c4c0b7076f1821da02e8458ad147324e0..9d517ca7eb5aad432249d34ed8a710588510bd21 100644 (file)
@@ -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++) {