mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2] driver: have dev_platform_ioremap_resource return error pointer
@ 2025-04-22  7:22 Ahmad Fatoum
  2025-04-22  9:31 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2025-04-22  7:22 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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

devm_request_mem_region doesn't return NULL on error on Linux and thus
it should neither in barebox. Fix this.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
  - clarify IS_ERR(resource::start) (Sascha)
---
 drivers/base/driver.c  | 11 ++++++++++-
 include/linux/device.h |  2 +-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index edba037fa2dd..85cec7efab46 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -549,7 +549,14 @@ void __iomem *dev_platform_get_and_ioremap_resource(struct device *dev,
 	res = dev_request_mem_resource(dev, num);
 	if (IS_ERR(res))
 		return IOMEM_ERR_PTR(PTR_ERR(res));
-	else if (WARN_ON(IS_ERR_VALUE(res->start)))
+
+	/* 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)
@@ -587,6 +594,8 @@ void __iomem *dev_request_mem_region(struct device *dev, int num)
 	struct resource *res;
 
 	res = dev_request_mem_resource(dev, num);
+	if (!IS_ERR(res) && WARN_ON(IS_ERR_VALUE(res->start)))
+		return IOMEM_ERR_PTR(res->start);
 	if (IS_ERR(res))
 		return ERR_CAST(res);
 
diff --git a/include/linux/device.h b/include/linux/device.h
index 66294910abb3..661d8b24730e 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -39,7 +39,7 @@ static inline void __iomem *dev_platform_ioremap_resource(struct device *dev,
 	 * so we don't need to do anything besides requesting the regions
 	 * and can leave the memory attributes unchanged.
 	 */
-	return dev_request_mem_region_err_null(dev, resource);
+	return dev_request_mem_region(dev, resource);
 }
 
 static inline void __iomem *devm_ioremap(struct device *dev,
-- 
2.39.5




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

end of thread, other threads:[~2025-04-22 10:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-22  7:22 [PATCH v2] driver: have dev_platform_ioremap_resource return error pointer Ahmad Fatoum
2025-04-22  9:31 ` Sascha Hauer

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