From patchwork Sun Jan 3 21:21:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivaylo Dimitrov X-Patchwork-Id: 7944061 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 77D5FBEEE5 for ; Sun, 3 Jan 2016 21:22:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 66E19203B7 for ; Sun, 3 Jan 2016 21:22:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7E3222038D for ; Sun, 3 Jan 2016 21:22:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752135AbcACVVg (ORCPT ); Sun, 3 Jan 2016 16:21:36 -0500 Received: from mail-wm0-f53.google.com ([74.125.82.53]:35970 "EHLO mail-wm0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752092AbcACVVg (ORCPT ); Sun, 3 Jan 2016 16:21:36 -0500 Received: by mail-wm0-f53.google.com with SMTP id l65so144096246wmf.1; Sun, 03 Jan 2016 13:21:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=ny6Dw1QOkyUxZXbke69/+voHM05UTbuIPTRwe11mezE=; b=wOFCEGxY2Ic5Jo4ybQa9tNwBpKJnMPq1mWqIwC2jR+TLvf1xjJl6H4mQi8KYSJm1vH eWtGODkY1wZ232IfQBSE7PtSHH9dLbBKSVprFhJNCtluJM8Ge7ZLOmWXPuQ/9V2ED77G 5LhXywmFKhzELd3lfTCuzdsvYdS2GmWhHfJvU9AChUGrgIo9GUjHv8blVoEvugYXKm86 yBD7GKO3/nhaqttsMJIr4PvgxtazwK438JiPu+UjZ7Sh63SAx1KCg3g5FMkWx/NTq0qc iVb/YprR/7wMMATOSP8d7qUL4ITjyYEtED23H1tA5Zp7BSMLUGJee3uJIhkLXteUHPix XfjQ== X-Received: by 10.194.116.97 with SMTP id jv1mr92216518wjb.38.1451856094804; Sun, 03 Jan 2016 13:21:34 -0800 (PST) Received: from localhost.localdomain ([46.249.74.23]) by smtp.gmail.com with ESMTPSA id z137sm48569344wmc.8.2016.01.03.13.21.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 03 Jan 2016 13:21:34 -0800 (PST) From: Ivaylo Dimitrov To: dmitry.torokhov@gmail.com Cc: pali.rohar@gmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Ivaylo Dimitrov Subject: [PATCH] input: gpio_keys: Fix check for disabling unsupported key Date: Sun, 3 Jan 2016 23:21:16 +0200 Message-Id: <1451856076-29045-1-git-send-email-ivo.g.dimitrov.75@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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);