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@barebox.org>
Subject: [PATCH 18/19] driver: make dev_platform_get_and_ioremap_resource() device-managed
Date: Wed, 28 Oct 2026 10:14:52 +0100	[thread overview]
Message-ID: <20261028092442.3300753-19-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20261028092442.3300753-1-a.fatoum@pengutronix.de>

From: Ahmad Fatoum <a.fatoum@barebox.org>

dev_platform_get_and_ioremap_resource() has the same -EBUSY problem on
deferred probe. Implement it on top of devm_request_mem_resource() as
well, move it to devres.c and give it the Linux name, which leaves
devm_platform_ioremap_resource() as a thin wrapper like upstream.

Assisted-by: Claude:opus-5-1m
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 drivers/base/devres.c                         | 25 ++++++++++++++++--
 drivers/base/driver.c                         | 26 -------------------
 drivers/hw_random/timeriomem-rng.c            |  2 +-
 drivers/mfd/atmel-flexcom.c                   |  2 +-
 drivers/phy/rockchip/phy-rockchip-usbdp.c     |  2 +-
 drivers/spi/spi-fsl-qspi.c                    |  2 +-
 drivers/video/rockchip/dw-mipi-dsi-rockchip.c |  2 +-
 include/driver.h                              |  6 ++---
 8 files changed, 31 insertions(+), 36 deletions(-)

diff --git a/drivers/base/devres.c b/drivers/base/devres.c
index cfa6cd3e3d9e..f1cf8e465074 100644
--- a/drivers/base/devres.c
+++ b/drivers/base/devres.c
@@ -207,16 +207,18 @@ struct resource *devm_request_mem_resource(struct device *dev, int num)
 EXPORT_SYMBOL(devm_request_mem_resource);
 
 /**
- * devm_platform_ioremap_resource() - request and map resource 'num' for a device
+ * devm_platform_get_and_ioremap_resource() - request and map resource 'num'
  * @dev: device to request the memory resource for
  * @num: index of the memory resource
+ * @out_res: where to store the requested resource, may be NULL
  *
  * barebox maps everything outside the RAM banks suitably for MMIO, so this
  * only requests the device-managed region.
  *
  * Return: a pointer to the registers or an ERR_PTR() on failure.
  */
-void __iomem *devm_platform_ioremap_resource(struct device *dev, int num)
+void __iomem *devm_platform_get_and_ioremap_resource(struct device *dev, int num,
+						     struct resource **out_res)
 {
 	struct resource *res;
 
@@ -233,6 +235,25 @@ void __iomem *devm_platform_ioremap_resource(struct device *dev, int num)
 	if (WARN_ON(IS_ERR_VALUE(res->start)))
 		return IOMEM_ERR_PTR(-EINVAL);
 
+	if (out_res)
+		*out_res = res;
+
 	return IOMEM(res->start);
 }
+EXPORT_SYMBOL(devm_platform_get_and_ioremap_resource);
+
+/**
+ * devm_platform_ioremap_resource() - request and map resource 'num' for a device
+ * @dev: device to request the memory resource for
+ * @num: index of the memory resource
+ *
+ * Like devm_platform_get_and_ioremap_resource(), but without handing the
+ * resource out.
+ *
+ * Return: a pointer to the registers or an ERR_PTR() on failure.
+ */
+void __iomem *devm_platform_ioremap_resource(struct device *dev, int num)
+{
+	return devm_platform_get_and_ioremap_resource(dev, num, NULL);
+}
 EXPORT_SYMBOL(devm_platform_ioremap_resource);
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index f87ecb200feb..33dad6ab6b16 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -557,32 +557,6 @@ void __iomem *dev_request_mem_region_by_name(struct device *dev,
 }
 EXPORT_SYMBOL(dev_request_mem_region_by_name);
 
-void __iomem *dev_platform_get_and_ioremap_resource(struct device *dev,
-						    int num,
-						    struct resource **out_res)
-{
-	struct resource *res;
-
-	res = dev_request_mem_resource(dev, num);
-	if (IS_ERR(res))
-		return IOMEM_ERR_PTR(PTR_ERR(res));
-
-	/* As everything is mapped 1:1 by default, drivers on unlucky
-	 * platforms can end up successfully requesting memory, but
-	 * getting a base address that looks like an error pointer.
-	 * Let's warn loudly about this case, as these drivers
-	 * should be using dev_request_mem_resource instead.
-	 */
-	if (WARN_ON(IS_ERR_VALUE(res->start)))
-		return IOMEM_ERR_PTR(-EINVAL);
-
-	if (out_res)
-		*out_res = res;
-
-	return IOMEM(res->start);
-}
-EXPORT_SYMBOL(dev_platform_get_and_ioremap_resource);
-
 struct resource *dev_request_mem_resource(struct device *dev, int num)
 {
 	struct resource *res;
diff --git a/drivers/hw_random/timeriomem-rng.c b/drivers/hw_random/timeriomem-rng.c
index 8d4705830653..4936c3c9676f 100644
--- a/drivers/hw_random/timeriomem-rng.c
+++ b/drivers/hw_random/timeriomem-rng.c
@@ -93,7 +93,7 @@ static int timeriomem_rng_probe(struct device *dev)
 	if (!priv)
 		return -ENOMEM;
 
-	priv->io_base = dev_platform_get_and_ioremap_resource(dev, 0, &res);
+	priv->io_base = devm_platform_get_and_ioremap_resource(dev, 0, &res);
 	if (IS_ERR(priv->io_base))
 		return PTR_ERR(priv->io_base);
 
diff --git a/drivers/mfd/atmel-flexcom.c b/drivers/mfd/atmel-flexcom.c
index 11daeafc5ffe..a7a650690e3f 100644
--- a/drivers/mfd/atmel-flexcom.c
+++ b/drivers/mfd/atmel-flexcom.c
@@ -35,7 +35,7 @@ static int atmel_flexcom_probe(struct device *dev)
 	if (opmode < ATMEL_FLEXCOM_MODE_USART || opmode > ATMEL_FLEXCOM_MODE_TWI)
 		return -EINVAL;
 
-	base = dev_platform_get_and_ioremap_resource(dev, 0, NULL);
+	base = devm_platform_get_and_ioremap_resource(dev, 0, NULL);
 	if (IS_ERR(base))
 		return dev_err_probe(dev, PTR_ERR(base), "Could not get memory region\n");
 
diff --git a/drivers/phy/rockchip/phy-rockchip-usbdp.c b/drivers/phy/rockchip/phy-rockchip-usbdp.c
index 9b08e60bbf6f..fee565cb231c 100644
--- a/drivers/phy/rockchip/phy-rockchip-usbdp.c
+++ b/drivers/phy/rockchip/phy-rockchip-usbdp.c
@@ -1053,7 +1053,7 @@ static int rk_udphy_probe(struct device *dev)
 	if (!udphy->cfgs)
 		return dev_err_probe(dev, -EINVAL, "missing match data\n");
 
-	base = dev_platform_get_and_ioremap_resource(dev, 0, &res);
+	base = devm_platform_get_and_ioremap_resource(dev, 0, &res);
 	if (IS_ERR(base))
 		return PTR_ERR(base);
 
diff --git a/drivers/spi/spi-fsl-qspi.c b/drivers/spi/spi-fsl-qspi.c
index cda0b06a5446..029f267453bc 100644
--- a/drivers/spi/spi-fsl-qspi.c
+++ b/drivers/spi/spi-fsl-qspi.c
@@ -798,7 +798,7 @@ static int fsl_qspi_probe(struct device *dev)
 		goto err_put_ctrl;
 	}
 
-	q->ahb_addr = dev_platform_get_and_ioremap_resource(dev, 1, &res);
+	q->ahb_addr = devm_platform_get_and_ioremap_resource(dev, 1, &res);
 	if (IS_ERR(q->ahb_addr)) {
 		ret = PTR_ERR(q->ahb_addr);
 		goto err_put_ctrl;
diff --git a/drivers/video/rockchip/dw-mipi-dsi-rockchip.c b/drivers/video/rockchip/dw-mipi-dsi-rockchip.c
index f065ebcefa00..ace989427422 100644
--- a/drivers/video/rockchip/dw-mipi-dsi-rockchip.c
+++ b/drivers/video/rockchip/dw-mipi-dsi-rockchip.c
@@ -1032,7 +1032,7 @@ static int dw_mipi_dsi_rockchip_probe(struct device *dev)
 	if (!dsi)
 		return -ENOMEM;
 
-	dsi->base = dev_platform_get_and_ioremap_resource(dev, 0, &res);
+	dsi->base = devm_platform_get_and_ioremap_resource(dev, 0, &res);
 	if (IS_ERR(dsi->base)) {
 		DRM_DEV_ERROR(dev, "Unable to get dsi registers\n");
 		return PTR_ERR(dsi->base);
diff --git a/include/driver.h b/include/driver.h
index 4005804bb1a9..e065e89547c9 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -196,9 +196,9 @@ struct resource *dev_request_mem_resource_by_name(struct device *dev,
 /* Like dev_request_mem_resource(), but released when the device goes away */
 struct resource *devm_request_mem_resource(struct device *dev, int num);
 
-void __iomem *dev_platform_get_and_ioremap_resource(struct device *dev,
-						    int num,
-						    struct resource **out_res);
+void __iomem *devm_platform_get_and_ioremap_resource(struct device *dev,
+						     int num,
+						     struct resource **out_res);
 
 /*
  * exlusively request register base 'num' for a device
-- 
2.47.3




  parent reply	other threads:[~2026-10-28  9:25 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28  9:14 [PATCH 00/19] driver: add devm_ support Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 01/19] commands: devunbind: refuse to unbind devices that were never bound Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 02/19] commands: devunbind: don't poison the active list entry Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 03/19] talloc: remove unused talloc_steal() and talloc_steal_children() Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 04/19] talloc: free children in a loop Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 05/19] talloc: add support for destructors Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 06/19] test: self: talloc: add destructor tests Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 07/19] talloc: add talloc_run_destructors() Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 08/19] mfd: pca9450: don't free device-managed memory in probe error path Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 09/19] video: backlight-pwm: allocate brightness levels with devm_kcalloc Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 10/19] driver: implement devm_ allocation helpers on top of talloc Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 11/19] devres: Provide kmalloc_obj*-style API for devm_kmalloc Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 12/19] memory: atmel-ebi: use generic devm_kzalloc() Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 13/19] driver: add devm_add_action() Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 14/19] test: self: add devm_ selftest Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 15/19] driver: add devm_request_mem_resource() Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 16/19] driver: make dev_platform_ioremap_resource() device-managed Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 17/19] treewide: rename dev_platform_ioremap_resource() to devm_platform_ioremap_resource() Ahmad Fatoum
2026-10-28  9:14 ` Ahmad Fatoum [this message]
2026-10-28  9:14 ` [PATCH 19/19] serial: stm32: request the registers with devm_request_mem_resource() Ahmad Fatoum

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=20261028092442.3300753-19-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=a.fatoum@barebox.org \
    --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