mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 1/5] driver: refactor probe return value handling into switch statement
@ 2024-02-19 17:29 Ahmad Fatoum
  2024-02-19 17:29 ` [PATCH v2 2/5] deep-probe: treat any probe deferral as permanent Ahmad Fatoum
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2024-02-19 17:29 UTC (permalink / raw)
  To: barebox; +Cc: mfe, Ahmad Fatoum

The return values of the bus probe function called inside device_probe()
are classified into 4 categories and they are checked by if statement
distributed across device_probe().

For clarity and easier changes, collect all of them into a switch
statement and while at it, use helpers to make use of %pe, list_move and
list_del_init instead of opencoding them.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
  - new patch
---
 drivers/base/driver.c | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 6548aec9b27b..4884e8fda8ef 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -129,12 +129,14 @@ int device_probe(struct device *dev)
 	list_add(&dev->active, &active_device_list);
 
 	ret = dev->bus->probe(dev);
-	if (ret == 0)
-		goto out;
 
-	if (ret == -EPROBE_DEFER) {
-		list_del(&dev->active);
-		list_add(&dev->active, &deferred);
+	depth--;
+
+	switch (ret) {
+	case 0:
+		return 0;
+	case -EPROBE_DEFER:
+		list_move(&dev->active, &deferred);
 
 		/*
 		 * -EPROBE_DEFER should never appear on a deep-probe machine so
@@ -144,19 +146,20 @@ int device_probe(struct device *dev)
 			dev_err(dev, "probe deferred\n");
 		else
 			dev_dbg(dev, "probe deferred\n");
-		goto out;
+
+		return -EPROBE_DEFER;
+	case -ENODEV:
+	case -ENXIO:
+		dev_dbg(dev, "probe failed: %pe\n", ERR_PTR(ret));
+		break;
+	default:
+		dev_err(dev, "probe failed: %pe\n", ERR_PTR(ret));
+		break;
+
 	}
 
-	list_del(&dev->active);
-	INIT_LIST_HEAD(&dev->active);
+	list_del_init(&dev->active);
 
-	if (ret == -ENODEV || ret == -ENXIO)
-		dev_dbg(dev, "probe failed: %s\n", strerror(-ret));
-	else
-		dev_err(dev, "probe failed: %s\n", strerror(-ret));
-
-out:
-	depth--;
 	return ret;
 }
 
-- 
2.39.2




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

end of thread, other threads:[~2024-02-20 11:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-19 17:29 [PATCH v2 1/5] driver: refactor probe return value handling into switch statement Ahmad Fatoum
2024-02-19 17:29 ` [PATCH v2 2/5] deep-probe: treat any probe deferral as permanent Ahmad Fatoum
2024-02-19 17:29 ` [PATCH v2 3/5] deep-probe: use IS_ERR_OR_NULL() instead of opencoding Ahmad Fatoum
2024-02-19 17:29 ` [PATCH v2 4/5] deep-probe: return -EPROBE_DEFER when ensuring probe fails Ahmad Fatoum
2024-02-19 17:29 ` [PATCH v2 5/5] phy: freescale: imx8mq-usb: make i.MX8MP support more explicit Ahmad Fatoum
2024-02-20 11:08 ` [PATCH v2 1/5] driver: refactor probe return value handling into switch statement Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox