Skip to contentSkip to conversation

input: gpio-keys: report error when invalid key number

PATCH Applied Peng Fan 2 participants 2 messages Aug 24, 2015

Subsystems (2)
lore
Share & tools
lore

Peng Fan

author
#0 lore raw

PATCH 1/1 input: gpio-keys: report error when invalid key number

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'.

Cc Dmitry Torokhov <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Alexander Stein <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Wolfram Sang <[email protected]>
Cc Fabio Estevam <[email protected]>
---
 drivers/input/keyboard/gpio_keys.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/input/keyboard/gpio_keys.c +5 -0
index ddf4045..b98f3b4 100644
@@ -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++) {
Signature · 1 line
1.8.4.5
maintainer Applied
#1 lore raw
Quoted 13 lines · Peng Fan

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'.

Quoted 8 lines
Cc Dmitry Torokhov <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Alexander Stein <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Wolfram Sang <[email protected]>
Cc Fabio Estevam <[email protected]>

Applied, thank you.

Quoted 23 lines
---
 drivers/input/keyboard/gpio_keys.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/input/keyboard/gpio_keys.c +5 -0
index ddf4045..b98f3b4 100644
@@ -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++) {
Signature · 1 line
1.8.4.5
Signature · 1 line
Dmitry