mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] drivers: don't propagate of_alias_get_id's -ENODEV out of probe
Date: Thu, 13 Nov 2025 08:59:03 +0100	[thread overview]
Message-ID: <20251113075904.990058-1-a.fatoum@pengutronix.de> (raw)

of_alias_get_id() returns -ENODEV on failure and propagating it gives
the user nothing to hint at there being a problem, so let's improve upon
that by either falling back to dynamic ID selections if possible or
returning a more fitting error code instead.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/gpio/gpio-clps711x.c  |  2 +-
 drivers/gpio/gpio-imx.c       |  5 ++---
 drivers/gpio/gpio-mxs.c       |  2 +-
 drivers/gpio/gpio-omap.c      |  5 ++---
 drivers/gpio/gpio-orion.c     |  5 ++---
 drivers/gpio/gpio-vf610.c     | 14 ++++----------
 drivers/spi/imx_spi.c         |  5 +----
 drivers/usb/imx/imx-usb-phy.c |  2 +-
 drivers/usb/musb/phy-am335x.c |  3 +--
 9 files changed, 15 insertions(+), 28 deletions(-)

diff --git a/drivers/gpio/gpio-clps711x.c b/drivers/gpio/gpio-clps711x.c
index a59bdd212a9c..8b8e91b825c5 100644
--- a/drivers/gpio/gpio-clps711x.c
+++ b/drivers/gpio/gpio-clps711x.c
@@ -15,7 +15,7 @@ static int clps711x_gpio_probe(struct device *dev)
 	struct bgpio_chip *bgc;
 
 	if (id < 0 || id > 4)
-		return -ENODEV;
+		return -EINVAL;
 
 	iores = dev_request_mem_resource(dev, 0);
 	if (IS_ERR(iores))
diff --git a/drivers/gpio/gpio-imx.c b/drivers/gpio/gpio-imx.c
index bb14c5639993..4fd56927d20d 100644
--- a/drivers/gpio/gpio-imx.c
+++ b/drivers/gpio/gpio-imx.c
@@ -138,9 +138,8 @@ static int imx_gpio_probe(struct device *dev)
 	imxgpio->chip.ops = &imx_gpio_ops;
 	if (dev->id < 0) {
 		imxgpio->chip.base = of_alias_get_id(dev->of_node, "gpio");
-		if (imxgpio->chip.base < 0)
-			return imxgpio->chip.base;
-		imxgpio->chip.base *= 32;
+		if (imxgpio->chip.base >= 0)
+			imxgpio->chip.base *= 32;
 	} else {
 		imxgpio->chip.base = dev->id * 32;
 	}
diff --git a/drivers/gpio/gpio-mxs.c b/drivers/gpio/gpio-mxs.c
index df698eb19167..00a9b72dfc86 100644
--- a/drivers/gpio/gpio-mxs.c
+++ b/drivers/gpio/gpio-mxs.c
@@ -112,7 +112,7 @@ static int mxs_gpio_probe(struct device *dev)
 	if (dev->id < 0) {
 		id = of_alias_get_id(dev->of_node, "gpio");
 		if (id < 0)
-			return id;
+			return -ENOENT;
 		mxsgpio->base = dev_get_mem_region(dev->parent, 0);
 		mxsgpio->chip.base = id * 32;
 	} else {
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index ed043286b7ff..f5abd63a90f8 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -135,9 +135,8 @@ static int omap_gpio_probe(struct device *dev)
 	omapgpio->chip.ops = &omap_gpio_ops;
 	if (dev->id < 0) {
 		omapgpio->chip.base = of_alias_get_id(dev->of_node, "gpio");
-		if (omapgpio->chip.base < 0)
-			return omapgpio->chip.base;
-		omapgpio->chip.base *= 32;
+		if (omapgpio->chip.base >= 0)
+			omapgpio->chip.base *= 32;
 	} else {
 		omapgpio->chip.base = dev->id * 32;
 	}
diff --git a/drivers/gpio/gpio-orion.c b/drivers/gpio/gpio-orion.c
index 0a1b50069b98..0760205c2610 100644
--- a/drivers/gpio/gpio-orion.c
+++ b/drivers/gpio/gpio-orion.c
@@ -95,10 +95,9 @@ static int orion_gpio_probe(struct device *dev)
 	gpio->chip.ops = &orion_gpio_ops;
 
 	id = of_alias_get_id(dev->of_node, "gpio");
-	if (id < 0)
-		return id;
+	if (id >= 0)
+		gpio->chip.base = id * 32;
 
-	gpio->chip.base = id * 32;
 	gpio->chip.ngpio = 32;
 	of_property_read_u32(dev->of_node, "ngpios", &gpio->chip.ngpio);
 
diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
index eefbaa70230f..5ce508469eb2 100644
--- a/drivers/gpio/gpio-vf610.c
+++ b/drivers/gpio/gpio-vf610.c
@@ -198,22 +198,16 @@ static int vf610_gpio_probe(struct device *dev)
 		port->gpio_base = IOMEM(iores->start);
 	}
 
+	port->chip.dev = dev;
 	port->chip.ops  = &vf610_gpio_ops;
 	if (dev->id < 0) {
 		port->chip.base = of_alias_get_id(dev->of_node, "gpio");
-		if (port->chip.base < 0) {
-			ret = port->chip.base;
-			dev_dbg(dev, "Failed to get GPIO alias\n");
-			goto free_port;
-		}
+		if (port->chip.base >= 0)
+			port->chip.base *= VF610_GPIO_PER_PORT;
 	} else {
-		port->chip.base = dev->id;
+		port->chip.base = dev->id * VF610_GPIO_PER_PORT;
 	}
 
-
-	port->chip.base *= VF610_GPIO_PER_PORT;
-	port->chip.dev = dev;
-
 	return gpiochip_add(&port->chip);
 
 free_port:
diff --git a/drivers/spi/imx_spi.c b/drivers/spi/imx_spi.c
index bfb4b413ebab..941a164b7631 100644
--- a/drivers/spi/imx_spi.c
+++ b/drivers/spi/imx_spi.c
@@ -603,10 +603,7 @@ static int imx_spi_probe(struct device *dev)
 		master->num_chipselect = pdata->num_chipselect;
 		imx->cs_array = pdata->chipselect;
 	} else if (IS_ENABLED(CONFIG_OFDEVICE)) {
-		ret = of_alias_get_id(dev->of_node, "spi");
-		if (ret < 0)
-			goto err_free;
-		master->bus_num = ret;
+		master->bus_num = of_alias_get_id(dev->of_node, "spi");;
 		imx_spi_dt_probe(imx);
 	}
 
diff --git a/drivers/usb/imx/imx-usb-phy.c b/drivers/usb/imx/imx-usb-phy.c
index 3dcaa1e1f438..7f9f5bebdee0 100644
--- a/drivers/usb/imx/imx-usb-phy.c
+++ b/drivers/usb/imx/imx-usb-phy.c
@@ -154,7 +154,7 @@ static int imx_usbphy_probe(struct device *dev)
 
 	ret = of_alias_get_id(np, "usbphy");
 	if (ret < 0) {
-		dev_dbg(dev, "failed to get alias id, errno %d\n", ret);
+		ret = dev_err_probe(dev, -ENOENT, "failed to get alias id\n");
 		goto err_free;
 	}
 	imxphy->port_id = ret;
diff --git a/drivers/usb/musb/phy-am335x.c b/drivers/usb/musb/phy-am335x.c
index f2a12182e021..d3ebbef302a1 100644
--- a/drivers/usb/musb/phy-am335x.c
+++ b/drivers/usb/musb/phy-am335x.c
@@ -45,8 +45,7 @@ static int am335x_phy_probe(struct device *dev)
 
 	am_usbphy->id = of_alias_get_id(dev->of_node, "phy");
 	if (am_usbphy->id < 0) {
-		dev_err(dev, "Missing PHY id: %d\n", am_usbphy->id);
-		ret = am_usbphy->id;
+		ret = dev_err_probe(dev, -ENOENT, "Missing PHY id\n");
 		goto err_release;
 	}
 
-- 
2.47.3




             reply	other threads:[~2025-11-13  7:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-13  7:59 Ahmad Fatoum [this message]
2025-11-14 13:03 ` Sascha Hauer

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=20251113075904.990058-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.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