From patchwork Wed Oct 19 23:41:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 9385571 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B0A1C60487 for ; Wed, 19 Oct 2016 23:41:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85E7B28B17 for ; Wed, 19 Oct 2016 23:41:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78A5528B5D; Wed, 19 Oct 2016 23:41:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D7E628B17 for ; Wed, 19 Oct 2016 23:41:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754100AbcJSXlN (ORCPT ); Wed, 19 Oct 2016 19:41:13 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:33708 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753009AbcJSXlM (ORCPT ); Wed, 19 Oct 2016 19:41:12 -0400 Received: by mail-pf0-f196.google.com with SMTP id i85so3681327pfa.0; Wed, 19 Oct 2016 16:41:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=BONJ3h/wsmn26jlmfoSNTVkD1bgEF5E43xkzTtC7LOo=; b=OPamPnCM2J6hda7fbcjfvASkVmXcaaZsOCr/DWC1t33kgn4eEc7QNq658T762KndJa 5+39URhVAUQHSHy/1VLctgAGy4lFO7d7+QEBRSkNIoHlFdYALxl7bq3FjtG0ujKSc2ZC hkLNelNB8KSZHR2mNHS4sYwY+P8uS5w+ror4bZDHSxbhQYiInGUElEuxm59P+/+crjST i5g280gWr1ofnS+UquR4Whe7FDYgeVUbwX1bJf5zU3ztBHqHtRtuyGBDUrn0CArIq6Qe d1LSL0VJ7z6ZW8x7T/PKrPcRnSFJUDTa6n1j5TuqkVgA40eK6JeurDNYOQO3gAG7a0NX o2AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=BONJ3h/wsmn26jlmfoSNTVkD1bgEF5E43xkzTtC7LOo=; b=YA8ylTMKgVbdOR8/FzP7uuItsCbWXBGO/2E9ZP/wi++fQRt2rD82hV/qVfrNB6jdyC B7pJavFOEAOIgG0LSV4ff8Xda9GRWChK+xdIzpkx8V0B1eMPxiqIqeHIIt370SkNXvCn NgyNYPjT9qDL62ALUK+SleFPmm1AqT2c6b2ZrYeFDQMk+QvnaRLX4E+/fUED2ySI8g1c V3lH0bT8HiNN1wYDe0+ffNJUUDJjo/WLINUIvginXyvKiiyqkEp/5hLCd1331e/4fU4f 1Gb+3l8KMwMwKhXf00pKDLSY75JBxIvKna+TAFF0CXHjAaehw6LZO4hPrv96nU0mKHmx CvNg== X-Gm-Message-State: AA6/9RliUsGy2z8XWMEfSGtTcfo2tvixfS9i5XkD8Howo5i5HkoRiIgeuvYBmIZi02gnWQ== X-Received: by 10.98.15.92 with SMTP id x89mr15699143pfi.29.1476920471139; Wed, 19 Oct 2016 16:41:11 -0700 (PDT) Received: from dtor-ws ([2620:0:1000:1311:9dfa:454a:fe8e:d782]) by smtp.gmail.com with ESMTPSA id v73sm66304499pfd.63.2016.10.19.16.41.09 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 19 Oct 2016 16:41:09 -0700 (PDT) Date: Wed, 19 Oct 2016 16:41:07 -0700 From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Hans de Goede , Geert Uytterhoeven , Aaron Lu , Mika Westerberg , Linus Walleij Subject: [PATCH] Input: gpio_keys_polled - always use gpiod_get_value_cansleep Message-ID: <20161019234107.GA2927@dtor-ws> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It does not matter if given GPIO may sleep or not when reading state, polling is always done in a non-atomic context, so we should always be able to simply use gpiod_get_value_cansleep(). Also let's note in the logs when we fail to read gpio state. Signed-off-by: Dmitry Torokhov Reviewed-by: Hans de Goede Acked-by: Linus Walleij --- drivers/input/keyboard/gpio_keys_polled.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c index daef8ea..3c79158 100644 --- a/drivers/input/keyboard/gpio_keys_polled.c +++ b/drivers/input/keyboard/gpio_keys_polled.c @@ -34,7 +34,6 @@ struct gpio_keys_button_data { int last_state; int count; int threshold; - int can_sleep; }; struct gpio_keys_polled_dev { @@ -76,16 +75,17 @@ static void gpio_keys_polled_check_state(struct input_polled_dev *dev, { int state; - if (bdata->can_sleep) - state = !!gpiod_get_value_cansleep(bdata->gpiod); - else - state = !!gpiod_get_value(bdata->gpiod); - - gpio_keys_button_event(dev, button, state); + state = gpiod_get_value_cansleep(bdata->gpiod); + if (unlikely(state < 0)) { + dev_err(input->dev.parent, + "failed to get gpio state: %d\n", state); + } else { + gpio_keys_button_event(dev, button, state); - if (state != bdata->last_state) { - bdata->count = 0; - bdata->last_state = state; + if (state != bdata->last_state) { + bdata->count = 0; + bdata->last_state = state; + } } } @@ -341,7 +341,6 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) } } - bdata->can_sleep = gpiod_cansleep(bdata->gpiod); bdata->last_state = -1; bdata->threshold = DIV_ROUND_UP(button->debounce_interval, pdata->poll_interval);