From patchwork Thu Aug 27 06:28:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 254541 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 175D9C433DF for ; Thu, 27 Aug 2020 06:28:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E51EA22B40 for ; Thu, 27 Aug 2020 06:28:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598509705; bh=uTlyu4Ggbom6cpomUXJKQ1GKWCdyLuFd3Pick+7iBao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=qiLluY9G93fPZ4nfX1LGYK8h2y91/zPCDMEv6T7jNleZlnb9Dt7HIlNWnUh2wNYDH hOpxevZDg0v7e5GI+4aqaxlAJUvUUvkNGPjtXudc6/X6pTjkhkC2yffsFDHYyo4pPt GE28L/6SeW7cABDeyujrdfKtGU7hhL5KAENEHGSY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727776AbgH0G2T (ORCPT ); Thu, 27 Aug 2020 02:28:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:40990 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726199AbgH0G2Q (ORCPT ); Thu, 27 Aug 2020 02:28:16 -0400 Received: from kozik-lap.mshome.net (unknown [194.230.155.216]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1DDEF22B49; Thu, 27 Aug 2020 06:28:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598509695; bh=uTlyu4Ggbom6cpomUXJKQ1GKWCdyLuFd3Pick+7iBao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nO8NuCnVpOQBELP+v/O22dxuv09RFbjRFq/uuriGLAgYqTIEZrsSmItlVXgtxwd7v t1/0qQ87dP254Xh9i2+lbDYE5U0jXlgQi1fC7bWJznJbyPfh1rVCxOf+GAITgh+pxM kjhL+WjNZJro0xiZqk1xVGhmCcNfZ5xUO6W4RLRs= From: Krzysztof Kozlowski To: Linus Walleij , Bartosz Golaszewski , Dmitry Torokhov , Nathan Chancellor , Nick Desaulniers , "Gustavo A. R. Silva" , Krzysztof Kozlowski , Hans de Goede , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, clang-built-linux@googlegroups.com Cc: Andy Shevchenko Subject: [PATCH v3 2/2] Input: gpio_keys - Simplify with dev_err_probe() Date: Thu, 27 Aug 2020 08:28:04 +0200 Message-Id: <20200827062804.16730-2-krzk@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200827062804.16730-1-krzk@kernel.org> References: <20200827062804.16730-1-krzk@kernel.org> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Common pattern of handling deferred probe can be simplified with dev_err_probe() and devm_fwnode_gpiod_get_optional(). Less code and the error value gets printed. Signed-off-by: Krzysztof Kozlowski Reviewed-by: Hans de Goede --- Changes since v2: 1. Preserve comment, 2. Include to fix warning on clang (reported by kbuild), 3. Fix use of uninitialized "error" variable. Changes since v1: 1. Use devm_fwnode_gpiod_get_optional --- drivers/input/keyboard/gpio_keys.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index f2d4e4daa818..160d94b1c2c0 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -494,23 +495,13 @@ static int gpio_keys_setup_key(struct platform_device *pdev, spin_lock_init(&bdata->lock); if (child) { - bdata->gpiod = devm_fwnode_gpiod_get(dev, child, - NULL, GPIOD_IN, desc); - if (IS_ERR(bdata->gpiod)) { - error = PTR_ERR(bdata->gpiod); - if (error == -ENOENT) { - /* - * GPIO is optional, we may be dealing with - * purely interrupt-driven setup. - */ - bdata->gpiod = NULL; - } else { - if (error != -EPROBE_DEFER) - dev_err(dev, "failed to get gpio: %d\n", - error); - return error; - } - } + /* + * GPIO is optional, we may be dealing with purely + * interrupt-driven setup. + */ + bdata->gpiod = devm_fwnode_gpiod_get_optional(dev, child, NULL, GPIOD_IN, desc); + if (IS_ERR(bdata->gpiod)) + return dev_err_probe(dev, PTR_ERR(bdata->gpiod), "failed to get gpio\n"); } else if (gpio_is_valid(button->gpio)) { /* * Legacy GPIO number, so request the GPIO here and