From: Krzysztof Kozlowski <krzk@kernel.org>
To: Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <bgolaszewski@baylibre.com>,
Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Nathan Chancellor <natechancellor@gmail.com>,
Nick Desaulniers <ndesaulniers@google.com>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
Krzysztof Kozlowski <krzk@kernel.org>,
Hans de Goede <hdegoede@redhat.com>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-input@vger.kernel.org, clang-built-linux@googlegroups.com
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Subject: [PATCH v3 2/2] Input: gpio_keys - Simplify with dev_err_probe()
Date: Thu, 27 Aug 2020 08:28:04 +0200 [thread overview]
Message-ID: <20200827062804.16730-2-krzk@kernel.org> (raw)
In-Reply-To: <20200827062804.16730-1-krzk@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 <krzk@kernel.org>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
---
Changes since v2:
1. Preserve comment,
2. Include <device.h> 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 <linux/sysctl.h>
#include <linux/proc_fs.h>
#include <linux/delay.h>
+#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/input.h>
#include <linux/gpio_keys.h>
@@ -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
--
2.17.1
next prev parent reply other threads:[~2020-08-27 6:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-27 6:28 [PATCH v3 1/2] gpio: Add devm_fwnode_gpiod_get_optional() helpers Krzysztof Kozlowski
2020-08-27 6:28 ` Krzysztof Kozlowski [this message]
2020-08-27 8:17 ` Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200827062804.16730-2-krzk@kernel.org \
--to=krzk@kernel.org \
--cc=andy.shevchenko@gmail.com \
--cc=bgolaszewski@baylibre.com \
--cc=clang-built-linux@googlegroups.com \
--cc=dmitry.torokhov@gmail.com \
--cc=gustavoars@kernel.org \
--cc=hdegoede@redhat.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=natechancellor@gmail.com \
--cc=ndesaulniers@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).