From: "Uwe Kleine-König" <ukleinek@debian.org>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
linux-iio@vger.kernel.org, Yves-Alexis Perez <corsac@debian.org>
Subject: [PATCH v2 2/3] iio: humidity: dht11: Emit error messages for probe failures
Date: Mon, 18 Jul 2022 21:42:57 +0200 [thread overview]
Message-ID: <20220718194258.181738-2-ukleinek@debian.org> (raw)
In-Reply-To: <20220718194258.181738-1-ukleinek@debian.org>
There are two exit points in the driver's probe function that fail
silently. From a user perspective this is unsatisfactory because the
device is unusable but there is no hint in the kernel log about the
actual problem which makes it unnecessarily hard to fix the problem.
Make use of dev_err_probe() to emit a problem indication which also does
the right thing if requesting the gpio return -EPROBE_DEFER.
Signed-off-by: Uwe Kleine-König <ukleinek@debian.org>
---
Changes since (implicit) v1:
- Make it actually compile. (It helps quite a lot to have the driver to
be tested enabled in the config when doing compile tests *sigh*)
- Fix a typo I added when manually splitting the original patch
drivers/iio/humidity/dht11.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/humidity/dht11.c b/drivers/iio/humidity/dht11.c
index 891b6bf0b4ca..0db4f7471319 100644
--- a/drivers/iio/humidity/dht11.c
+++ b/drivers/iio/humidity/dht11.c
@@ -293,6 +293,7 @@ static int dht11_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
struct dht11 *dht11;
struct iio_dev *iio;
+ int ret;
iio = devm_iio_device_alloc(dev, sizeof(*dht11));
if (!iio)
@@ -302,7 +303,8 @@ static int dht11_probe(struct platform_device *pdev)
dht11->dev = dev;
dht11->gpiod = devm_gpiod_get(dev, NULL, GPIOD_IN);
if (IS_ERR(dht11->gpiod))
- return PTR_ERR(dht11->gpiod);
+ return dev_err_probe(dev, PTR_ERR(dht11->gpiod),
+ "Failed to acquire GPIO\n");
dht11->irq = gpiod_to_irq(dht11->gpiod);
if (dht11->irq < 0) {
@@ -323,7 +325,11 @@ static int dht11_probe(struct platform_device *pdev)
iio->channels = dht11_chan_spec;
iio->num_channels = ARRAY_SIZE(dht11_chan_spec);
- return devm_iio_device_register(dev, iio);
+ ret = devm_iio_device_register(dev, iio);
+ if (ret < 0)
+ return dev_err_probe(dev, ret, "Failed to register iio device\n");
+
+ return 0;
}
static struct platform_driver dht11_driver = {
--
2.36.1
next prev parent reply other threads:[~2022-07-18 19:43 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-18 19:42 [PATCH v2 1/3] iio: humidity: dht11: Don't warn on memory allocation failure Uwe Kleine-König
2022-07-18 19:42 ` Uwe Kleine-König [this message]
2022-07-18 20:27 ` [PATCH v2 2/3] iio: humidity: dht11: Emit error messages for probe failures Andy Shevchenko
2022-07-18 20:35 ` Uwe Kleine-König
2022-07-19 8:48 ` Jonathan Cameron
2022-07-19 9:08 ` Andy Shevchenko
2022-07-18 19:42 ` [PATCH v2 3/3] iio: humidity: dht11: Use dev_err_probe consistently Uwe Kleine-König
2022-07-18 20:29 ` Andy Shevchenko
2022-07-18 20:32 ` Andy Shevchenko
2022-07-19 8:47 ` Jonathan Cameron
2022-07-18 20:26 ` [PATCH v2 1/3] iio: humidity: dht11: Don't warn on memory allocation failure 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=20220718194258.181738-2-ukleinek@debian.org \
--to=ukleinek@debian.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=corsac@debian.org \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
/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