From patchwork Fri Feb 19 10:04:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 8359141 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C87009F372 for ; Fri, 19 Feb 2016 10:04:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E164D20416 for ; Fri, 19 Feb 2016 10:04:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B3952203F7 for ; Fri, 19 Feb 2016 10:04:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1426991AbcBSKEj (ORCPT ); Fri, 19 Feb 2016 05:04:39 -0500 Received: from albert.telenet-ops.be ([195.130.137.90]:41563 "EHLO albert.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757364AbcBSKEh (ORCPT ); Fri, 19 Feb 2016 05:04:37 -0500 Received: from ayla.of.borg ([84.195.106.123]) by albert.telenet-ops.be with bizsmtp id LA4Y1s00q2fm56U06A4Ygj; Fri, 19 Feb 2016 11:04:33 +0100 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.82) (envelope-from ) id 1aWhvM-0002UL-Qf; Fri, 19 Feb 2016 11:04:32 +0100 Received: from geert by ramsan with local (Exim 4.82) (envelope-from ) id 1aWhvO-0001Xz-Aw; Fri, 19 Feb 2016 11:04:34 +0100 From: Geert Uytterhoeven To: Dmitry Torokhov , Aaron Lu , Mika Westerberg , "Rafael J. Wysocki" Cc: Linus Walleij , Alexandre Courbot , linux-input@vger.kernel.org, linux-gpio@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] input: gpio_keys_polled: Correct check for invalid gpiod Date: Fri, 19 Feb 2016 11:04:33 +0100 Message-Id: <1455876273-5913-1-git-send-email-geert+renesas@glider.be> 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 At this point in gpio_keys_polled_probe(), button->gpiod contains either a pointer to a GPIO descriptor or NULL, because: - gpio_keys_polled_get_devtree_pdata() fills in button->gpiod only if devm_get_gpiod_from_child() succeeded, - gpio_to_desc() returns NULL on failure, not an ERR_PTR(), - button->gpiod is untouched if it was NULL, and button->gpio is not valid. Hence check for NULL only, and return -EINVAL on failure. Signed-off-by: Geert Uytterhoeven Reviewed-by: Mika Westerberg --- Question: Should it return -ENOENT instead? next-20160219:drivers/leds/leds-gpio.c uses -EINVAL, too. --- drivers/input/keyboard/gpio_keys_polled.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c index 62bdb1d48c49dbd9..1ef3c66099a50d72 100644 --- a/drivers/input/keyboard/gpio_keys_polled.c +++ b/drivers/input/keyboard/gpio_keys_polled.c @@ -330,8 +330,8 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) button->gpiod = gpio_to_desc(button->gpio); } - if (IS_ERR(button->gpiod)) - return PTR_ERR(button->gpiod); + if (!button->gpiod) + return -EINVAL; bdata->can_sleep = gpiod_cansleep(button->gpiod); bdata->last_state = -1;