mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
To: dmitry.torokhov@gmail.com
Cc: pali.rohar@gmail.com, linux-input@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
Subject: [PATCH] input: gpio_keys: Fix check for disabling unsupported key
Date: Sun,  3 Jan 2016 23:21:16 +0200	[thread overview]
Message-ID: <1451856076-29045-1-git-send-email-ivo.g.dimitrov.75@gmail.com> (raw)

Commit 4ea14a53d8f881034fa9e186653821c4e3d9a8fb ("Input: gpio-keys -
report error when disabling unsupported key") tried to prevent an
unsupported key to disabled. Unfortunately it effectively broke the driver
in a way so no key is possible to be disabled. Fix that by providing the
correct verify logic.

Signed-off-by: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
---
 drivers/input/keyboard/gpio_keys.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index bef317f..a371805 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -226,22 +226,32 @@ static ssize_t gpio_keys_attr_store_helper(struct gpio_keys_drvdata *ddata,
 		goto out;
 
 	/* First validate */
-	for (i = 0; i < ddata->pdata->nbuttons; i++) {
-		struct gpio_button_data *bdata = &ddata->data[i];
+	for (i = 0; i < n_events; i++) {
+		int j;
 
-		if (bdata->button->type != type)
+		if (!test_bit(i, bits))
 			continue;
 
-		if (test_bit(bdata->button->code, bits) &&
-		    !bdata->button->can_disable) {
+		for (j = 0; j < ddata->pdata->nbuttons; j++) {
+			struct gpio_button_data *bdata = &ddata->data[j];
+
+			if (bdata->button->type != type)
+				continue;
+
+			if (bdata->button->code == i) {
+				if (!bdata->button->can_disable) {
+					error = -EINVAL;
+					goto out;
+				}
+				break;
+			}
+		}
+
+		if (j == ddata->pdata->nbuttons) {
 			error = -EINVAL;
 			goto out;
 		}
-	}
 
-	if (i == ddata->pdata->nbuttons) {
-		error = -EINVAL;
-		goto out;
 	}
 
 	mutex_lock(&ddata->disable_lock);
-- 
1.9.1


             reply	other threads:[~2016-01-03 21:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-03 21:21 Ivaylo Dimitrov [this message]
2016-01-05  1:19 ` Dmitry Torokhov
2016-01-05  7:24   ` Ivaylo Dimitrov
2016-01-06 22:38     ` Dmitry Torokhov
2016-01-10 17:39       ` Ivaylo Dimitrov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1451856076-29045-1-git-send-email-ivo.g.dimitrov.75@gmail.com \
    --to=ivo.g.dimitrov.75@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pali.rohar@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®