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] iio: humidity: dht11: Improve error reporting in .probe()
Date: Thu, 30 Jun 2022 08:35:28 +0200 [thread overview]
Message-ID: <20220630063528.205327-1-ukleinek@debian.org> (raw)
Don't emit a message for -ENOMEM, the kernel is already loud enough in
this case. Add a message if getting the GPIO or registering the iio
device fails and use dev_err_probe for improved behaviour on
-EPROBE_DEFER.
Signed-off-by: Uwe Kleine-König <ukleinek@debian.org>
---
drivers/iio/humidity/dht11.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/humidity/dht11.c b/drivers/iio/humidity/dht11.c
index c97e25448772..d8b2cb3ef81e 100644
--- a/drivers/iio/humidity/dht11.c
+++ b/drivers/iio/humidity/dht11.c
@@ -293,24 +293,23 @@ 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) {
- dev_err(dev, "Failed to allocate IIO device\n");
+ if (!iio)
return -ENOMEM;
- }
dht11 = iio_priv(iio);
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) {
- dev_err(dev, "GPIO %d has no interrupt\n", desc_to_gpio(dht11->gpiod));
- return -EINVAL;
- }
+ if (dht11->irq < 0)
+ return dev_err_probe(dev, -EINVAL, "GPIO %d has no interrupt\n",
+ desc_to_gpio(dht11->gpiod));
dht11->timestamp = ktime_get_boottime_ns() - DHT11_DATA_VALID_TIME - 1;
dht11->num_edges = -1;
@@ -325,7 +324,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 = {
base-commit: f2906aa863381afb0015a9eb7fefad885d4e5a56
--
2.36.1
next reply other threads:[~2022-06-30 6:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-30 6:35 Uwe Kleine-König [this message]
2022-06-30 7:17 ` [PATCH] iio: humidity: dht11: Improve error reporting in .probe() Andy Shevchenko
2022-06-30 10:14 ` Uwe Kleine-König
2022-06-30 10:26 ` Andy Shevchenko
2022-06-30 14:15 ` Uwe Kleine-König
2022-07-16 16:51 ` Jonathan Cameron
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=20220630063528.205327-1-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