[PATCH 08/15] driver: implement dev_request_resource

Ahmad Fatoum a.fatoum at pengutronix.de
Wed Jan 11 09:40:16 PST 2023


dev_request_resource is useful for porting kernel drivers that use
devm_request_source on a resource retrieved via <linux/of_address.h>.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/base/driver.c | 19 +++++++++++++++----
 include/driver.h      |  3 +++
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 839a8513fc25..efbffcdddbcb 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -453,8 +453,19 @@ struct resource *dev_get_resource_by_name(struct device *dev,
 	return ERR_PTR(-ENOENT);
 }
 
-struct resource *dev_request_mem_resource_by_name(struct device *dev,
-						  const char *name)
+static struct resource *dev_request_iomem_resource(struct device *dev,
+						   const struct resource *res)
+{
+	return request_iomem_region(dev_name(dev), res->start, res->end);
+}
+
+int dev_request_resource(struct device *dev, const struct resource *res)
+{
+	return PTR_ERR_OR_ZERO(dev_request_iomem_resource(dev, res));
+}
+EXPORT_SYMBOL(dev_request_resource);
+
+struct resource *dev_request_mem_resource_by_name(struct device *dev, const char *name)
 {
 	struct resource *res;
 
@@ -462,7 +473,7 @@ struct resource *dev_request_mem_resource_by_name(struct device *dev,
 	if (IS_ERR(res))
 		return ERR_CAST(res);
 
-	return request_iomem_region(dev_name(dev), res->start, res->end);
+	return dev_request_iomem_resource(dev, res);
 }
 EXPORT_SYMBOL(dev_request_mem_resource_by_name);
 
@@ -487,7 +498,7 @@ struct resource *dev_request_mem_resource(struct device *dev, int num)
 	if (IS_ERR(res))
 		return ERR_CAST(res);
 
-	return request_iomem_region(dev_name(dev), res->start, res->end);
+	return dev_request_iomem_resource(dev, res);
 }
 
 void __iomem *dev_request_mem_region_err_null(struct device *dev, int num)
diff --git a/include/driver.h b/include/driver.h
index e1b1ebde5b5f..b7d6ea1e52c1 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -220,6 +220,9 @@ struct resource *dev_get_resource_by_name(struct device *dev,
 					  unsigned long type,
 					  const char *name);
 
+int dev_request_resource(struct device *dev,
+			 const struct resource *res);
+
 /*
  * exlusively request register base 'name' for a device
  */
-- 
2.30.2




More information about the barebox mailing list