From patchwork Fri Feb 19 09:58:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 585119 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 380DB14031E for ; Fri, 19 Feb 2016 20:59:14 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1427500AbcBSJ65 (ORCPT ); Fri, 19 Feb 2016 04:58:57 -0500 Received: from andre.telenet-ops.be ([195.130.132.53]:52540 "EHLO andre.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1427495AbcBSJ6f (ORCPT ); Fri, 19 Feb 2016 04:58:35 -0500 Received: from ayla.of.borg ([84.195.106.123]) by andre.telenet-ops.be with bizsmtp id L9yT1s00s2fm56U019yTPA; Fri, 19 Feb 2016 10:58:27 +0100 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.82) (envelope-from ) id 1aWhpT-0002TU-E3; Fri, 19 Feb 2016 10:58:27 +0100 Received: from geert by ramsan with local (Exim 4.82) (envelope-from ) id 1aWhpU-0001K9-Rx; Fri, 19 Feb 2016 10:58:28 +0100 From: Geert Uytterhoeven To: Linus Walleij , Alexandre Courbot Cc: Olliver Schinagl , linux-gpio@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] input: gpio_keys_polled: Correct check for invalid gpiod Date: Fri, 19 Feb 2016 10:58:26 +0100 Message-Id: <1455875906-5048-1-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 1.9.1 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org 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 --- Question: Should it return -ENOENT instead? --- 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;