diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2024-02-19 18:29:21 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2024-02-20 12:08:30 +0100 |
commit | 6e08b4ab5bec01146f3152579152872258c0ac24 (patch) | |
tree | fa42669ee7cad07c298a8e72e954b773ec5c2b32 | |
parent | b305ee5e04394ef3d7e75078fa5195e1b27a07e6 (diff) | |
download | barebox-6e08b4ab5bec.tar.gz barebox-6e08b4ab5bec.tar.xz |
driver: refactor probe return value handling into switch statement
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>
Link: https://lore.barebox.org/20240219172925.3798024-1-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | drivers/base/driver.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 8bd187eef5..5ead5d961e 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; - } - list_del(&dev->active); - INIT_LIST_HEAD(&dev->active); + 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; - if (ret == -ENODEV || ret == -ENXIO) - dev_dbg(dev, "probe failed: %s\n", strerror(-ret)); - else - dev_err(dev, "probe failed: %s\n", strerror(-ret)); + } + + list_del_init(&dev->active); -out: - depth--; return ret; } |