linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/2] driver core: platform: Add the helper function devm_platform_get_and_ioremap_resource_byname()
@ 2021-09-02  5:24 Cai Huoqing
  2021-09-02  5:38 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 2+ messages in thread
From: Cai Huoqing @ 2021-09-02  5:24 UTC (permalink / raw)
  To: caihuoqing; +Cc: Greg Kroah-Hartman, Rafael J. Wysocki, linux-kernel

Since provide the helper function devm_platform_ioremap_resource_byname()
which is wrap platform_get_resource_byname() and devm_ioremap_resource().
But sometimes, many drivers still need to use the resource variables
obtained by platform_get_resource(). In these cases, provide this helper
function devm_platform_get_and_ioremap_resource_byname().

Signed-off-by: Cai Huoqing <caihuoqing@baidu.com>
---
 drivers/base/platform.c         | 30 ++++++++++++++++++++++++++----
 include/linux/platform_device.h |  3 +++
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 52a1b94428c8..29e3ad6dde70 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -124,6 +124,31 @@ void __iomem *devm_platform_ioremap_resource(struct platform_device *pdev,
 }
 EXPORT_SYMBOL_GPL(devm_platform_ioremap_resource);
 
+/**
+ * devm_platform_get_and_ioremap_resource_byname - call devm_ioremap_resource() for a
+ *						   platform device and get resource
+ *
+ * @pdev: platform device to use both for memory resource lookup as well as
+ *        resource management
+ * @name: name of the resource
+ * @res: optional output parameter to store a pointer to the obtained resource.
+ *
+ * Return: a pointer to the remapped memory or an ERR_PTR() encoded error code
+ * on failure.
+ */
+void __iomem *
+devm_platform_get_and_ioremap_resource_byname(struct platform_device *pdev,
+					      const char *name, struct resource **res)
+{
+	struct resource *r;
+
+	r = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
+	if (res)
+		*res = r;
+	return devm_ioremap_resource(&pdev->dev, r);
+}
+EXPORT_SYMBOL_GPL(devm_platform_get_and_ioremap_resource_byname);
+
 /**
  * devm_platform_ioremap_resource_byname - call devm_ioremap_resource for
  *					   a platform device, retrieve the
@@ -140,10 +165,7 @@ void __iomem *
 devm_platform_ioremap_resource_byname(struct platform_device *pdev,
 				      const char *name)
 {
-	struct resource *res;
-
-	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
-	return devm_ioremap_resource(&pdev->dev, res);
+	return devm_platform_get_and_ioremap_resource_byname(pdev, name, NULL);
 }
 EXPORT_SYMBOL_GPL(devm_platform_ioremap_resource_byname);
 #endif /* CONFIG_HAS_IOMEM */
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 07e1bba45243..a20f3ecc1cd8 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -66,6 +66,9 @@ extern void __iomem *
 devm_platform_ioremap_resource(struct platform_device *pdev,
 			       unsigned int index);
 extern void __iomem *
+devm_platform_get_and_ioremap_resource_byname(struct platform_device *pdev,
+					      const char *name, struct resource **res);
+extern void __iomem *
 devm_platform_ioremap_resource_byname(struct platform_device *pdev,
 				      const char *name);
 extern int platform_get_irq(struct platform_device *, unsigned int);
-- 
2.25.1


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

* Re: [PATCH 2/2] driver core: platform: Add the helper function devm_platform_get_and_ioremap_resource_byname()
  2021-09-02  5:24 [PATCH 2/2] driver core: platform: Add the helper function devm_platform_get_and_ioremap_resource_byname() Cai Huoqing
@ 2021-09-02  5:38 ` Greg Kroah-Hartman
  0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2021-09-02  5:38 UTC (permalink / raw)
  To: Cai Huoqing; +Cc: Rafael J. Wysocki, linux-kernel

On Thu, Sep 02, 2021 at 01:24:58PM +0800, Cai Huoqing wrote:
> Since provide the helper function devm_platform_ioremap_resource_byname()
> which is wrap platform_get_resource_byname() and devm_ioremap_resource().
> But sometimes, many drivers still need to use the resource variables
> obtained by platform_get_resource(). In these cases, provide this helper
> function devm_platform_get_and_ioremap_resource_byname().
> 
> Signed-off-by: Cai Huoqing <caihuoqing@baidu.com>
> ---
>  drivers/base/platform.c         | 30 ++++++++++++++++++++++++++----
>  include/linux/platform_device.h |  3 +++
>  2 files changed, 29 insertions(+), 4 deletions(-)

We can not add new functions that no one uses.  Please resend this as
part of a patch series that uses the new function so we can be sure to
see if it really is needed or not.

Also your patch series was not threaded properly, please use 'git
send-email' for your future patches.

thanks,

greg k-h

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

end of thread, other threads:[~2021-09-02  5:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-02  5:24 [PATCH 2/2] driver core: platform: Add the helper function devm_platform_get_and_ioremap_resource_byname() Cai Huoqing
2021-09-02  5:38 ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).