All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] iio: humidity: dht11: Don't warn on memory allocation failure
@ 2022-07-18 19:35 Uwe Kleine-König
  2022-07-18 19:35 ` [PATCH 2/3] iio: humidity: dht11: Emit error messages for probe failures Uwe Kleine-König
  2022-07-18 19:35 ` [PATCH 3/3] iio: humidity: dht11: Use dev_err_probe consistently Uwe Kleine-König
  0 siblings, 2 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2022-07-18 19:35 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Lars-Peter Clausen, Andy Shevchenko, linux-iio, Yves-Alexis Perez

The kernel is already quite noisy if a memory allocation fails. So it's
the usual policy to not add another message on the driver level.

Drop the error message accordingly.

Signed-off-by: Uwe Kleine-König <ukleinek@debian.org>
---
 drivers/iio/humidity/dht11.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/iio/humidity/dht11.c b/drivers/iio/humidity/dht11.c
index c97e25448772..891b6bf0b4ca 100644
--- a/drivers/iio/humidity/dht11.c
+++ b/drivers/iio/humidity/dht11.c
@@ -295,10 +295,8 @@ static int dht11_probe(struct platform_device *pdev)
 	struct iio_dev *iio;
 
 	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;

base-commit: f2906aa863381afb0015a9eb7fefad885d4e5a56
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/3] iio: humidity: dht11: Emit error messages for probe failures
  2022-07-18 19:35 [PATCH 1/3] iio: humidity: dht11: Don't warn on memory allocation failure Uwe Kleine-König
@ 2022-07-18 19:35 ` Uwe Kleine-König
  2022-07-18 19:35 ` [PATCH 3/3] iio: humidity: dht11: Use dev_err_probe consistently Uwe Kleine-König
  1 sibling, 0 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2022-07-18 19:35 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Lars-Peter Clausen, Andy Shevchenko, linux-iio, Yves-Alexis Perez

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>
---
 drivers/iio/humidity/dht11.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/humidity/dht11.c b/drivers/iio/humidity/dht11.c
index 891b6bf0b4ca..6182f4d2e9fc 100644
--- a/drivers/iio/humidity/dht11.c
+++ b/drivers/iio/humidity/dht11.c
@@ -302,7 +302,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 aquire GPIO\n");
 
 	dht11->irq = gpiod_to_irq(dht11->gpiod);
 	if (dht11->irq < 0) {
@@ -323,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 = {
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 3/3] iio: humidity: dht11: Use dev_err_probe consistently
  2022-07-18 19:35 [PATCH 1/3] iio: humidity: dht11: Don't warn on memory allocation failure Uwe Kleine-König
  2022-07-18 19:35 ` [PATCH 2/3] iio: humidity: dht11: Emit error messages for probe failures Uwe Kleine-König
@ 2022-07-18 19:35 ` Uwe Kleine-König
  1 sibling, 0 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2022-07-18 19:35 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Lars-Peter Clausen, Andy Shevchenko, linux-iio, Yves-Alexis Perez

All but one error path use dev_err_probe() to emit a message. Use the same
incarnation for the remaining exit point for consistency.

Signed-off-by: Uwe Kleine-König <ukleinek@debian.org>
---
 drivers/iio/humidity/dht11.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/humidity/dht11.c b/drivers/iio/humidity/dht11.c
index 6182f4d2e9fc..50d2431c938b 100644
--- a/drivers/iio/humidity/dht11.c
+++ b/drivers/iio/humidity/dht11.c
@@ -306,10 +306,9 @@ static int dht11_probe(struct platform_device *pdev)
 				     "Failed to aquire 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;
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-07-18 19:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-18 19:35 [PATCH 1/3] iio: humidity: dht11: Don't warn on memory allocation failure Uwe Kleine-König
2022-07-18 19:35 ` [PATCH 2/3] iio: humidity: dht11: Emit error messages for probe failures Uwe Kleine-König
2022-07-18 19:35 ` [PATCH 3/3] iio: humidity: dht11: Use dev_err_probe consistently Uwe Kleine-König

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.