[PATCH v2 0/3] drivers: Add the helper function devm_platform_get_and_ioremap_resource_byname()

STALE1864d

7 messages, 2 authors, 2021-09-02 · open the first message on its own page

[PATCH v2 0/3] drivers: Add the helper function devm_platform_get_and_ioremap_resource_byname()

From: Cai Huoqing <hidden>
Date: 2021-09-02 06:37:17

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 case, provide this helper function
devm_platform_get_and_ioremap_resource_byname().

devm_platform_get_and_ioremap_resource_byname will be used:
 .../platform/sti/c8sectpfe/c8sectpfe-core.c   |  7 ++---
 drivers/pci/controller/pcie-mediatek-gen3.c   |  5 +---


Cai Huoqing (3):
  driver core: platform: Add the helper function
    devm_platform_get_and_ioremap_resource_byname()
  media: sti/c8sectpfe: Make use of the helper function
    devm_platform_get_and_ioremap_resource_byname()
  PCI: mediatek-gen3: Make use of the helper function
    devm_platform_get_and_ioremap_resource_byname()

 drivers/base/platform.c                       | 30 ++++++++++++++++---
 .../platform/sti/c8sectpfe/c8sectpfe-core.c   |  7 ++---
 drivers/pci/controller/pcie-mediatek-gen3.c   |  5 +---
 include/linux/platform_device.h               |  3 ++
 4 files changed, 32 insertions(+), 13 deletions(-)

-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

[PATCH v2 3/3] PCI: mediatek-gen3: Make use of the helper function devm_platform_get_and_ioremap_resource_byname()

From: Cai Huoqing <hidden>
Date: 2021-09-02 06:37:19

Use the devm_platform_get_and_ioremap_resource_byname() helper
instead of calling platform_get_resource_byname() and
devm_ioremap_resource() separately.

Signed-off-by: Cai Huoqing <redacted>
---
v1->v2: Use devm_platform_get_and_ioremap_resource_byname()
	instead of devm_platform_ioremap_resource_byname().

 drivers/pci/controller/pcie-mediatek-gen3.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/pci/controller/pcie-mediatek-gen3.c b/drivers/pci/controller/pcie-mediatek-gen3.c
index 17c59b0d6978..27009da62ec1 100644
--- a/drivers/pci/controller/pcie-mediatek-gen3.c
+++ b/drivers/pci/controller/pcie-mediatek-gen3.c
@@ -715,10 +715,7 @@ static int mtk_pcie_parse_port(struct mtk_pcie_port *port)
 	struct resource *regs;
 	int ret;
 
-	regs = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcie-mac");
-	if (!regs)
-		return -EINVAL;
-	port->base = devm_ioremap_resource(dev, regs);
+	port->base = devm_platform_get_and_ioremap_resource_byname(pdev, "pcie-mac", &regs);
 	if (IS_ERR(port->base)) {
 		dev_err(dev, "failed to map register base\n");
 		return PTR_ERR(port->base);
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

[PATCH v2 1/3] driver core: platform: Add the helper function devm_platform_get_and_ioremap_resource_byname()

From: Cai Huoqing <hidden>
Date: 2021-09-02 06:37:21

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 <redacted>
---
v1->v2: Resend this patch as part of a patch series that uses
	the new function. 

 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 652531f67135..34bb581338d9 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 7c96f169d274..50eb1a5b503a 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


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

[PATCH v2 2/3] media: sti/c8sectpfe: Make use of the helper function devm_platform_get_and_ioremap_resource_byname()

From: Cai Huoqing <hidden>
Date: 2021-09-02 06:37:22

Use the devm_platform_get_and_ioremap_resource_byname() helper
instead of calling platform_get_resource_byname() and
devm_ioremap_resource() separately.

Signed-off-by: Cai Huoqing <redacted>
---
v1->v2: Use devm_platform_get_and_ioremap_resource_byname()
	instead of devm_platform_ioremap_resource_byname().

 drivers/media/platform/sti/c8sectpfe/c8sectpfe-core.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/drivers/media/platform/sti/c8sectpfe/c8sectpfe-core.c b/drivers/media/platform/sti/c8sectpfe/c8sectpfe-core.c
index 02dc78bd7fab..8d57970c196c 100644
--- a/drivers/media/platform/sti/c8sectpfe/c8sectpfe-core.c
+++ b/drivers/media/platform/sti/c8sectpfe/c8sectpfe-core.c
@@ -676,14 +676,11 @@ static int c8sectpfe_probe(struct platform_device *pdev)
 
 	fei->dev = dev;
 
-	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "c8sectpfe");
-	fei->io = devm_ioremap_resource(dev, res);
+	fei->io = devm_platform_get_and_ioremap_resource_byname(pdev, "c8sectpfe", &res);
 	if (IS_ERR(fei->io))
 		return PTR_ERR(fei->io);
 
-	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
-					"c8sectpfe-ram");
-	fei->sram = devm_ioremap_resource(dev, res);
+	fei->sram = devm_platform_get_and_ioremap_resource_byname(pdev, "c8sectpfe-ram", &res);
 	if (IS_ERR(fei->sram))
 		return PTR_ERR(fei->sram);
 
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Re: [PATCH v2 1/3] driver core: platform: Add the helper function devm_platform_get_and_ioremap_resource_byname()

From: Greg KH <gregkh@linuxfoundation.org>
Date: 2021-09-02 06:52:56

On Thu, Sep 02, 2021 at 02:37:00PM +0800, Cai Huoqing wrote:
quoted hunk
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 <redacted>
---
v1->v2: Resend this patch as part of a patch series that uses
	the new function. 

 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 652531f67135..34bb581338d9 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;
You forgot to check the return value of this call :(

Which means you did not test this?  Why not?

But step back, _WHY_ is this needed at all?  How deep are we going to
get with the "devm_platform_get_and_do_this_and_that_and_that" type
functions here?

You show 2 users of this call, and they save what, 1-2 lines of code
here?

What is the real need for this?

thanks,

greg k-h

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Re: [PATCH v2 1/3] driver core: platform: Add the helper function devm_platform_get_and_ioremap_resource_byname()

From: Cai Huoqing <hidden>
Date: 2021-09-02 08:07:29

On 02 Sep 21 08:52:45, Greg KH wrote:
On Thu, Sep 02, 2021 at 02:37:00PM +0800, Cai Huoqing wrote:
quoted
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 <redacted>
---
v1->v2: Resend this patch as part of a patch series that uses
	the new function. 

 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 652531f67135..34bb581338d9 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;
You forgot to check the return value of this call :(
devm_ioremap_resource wiil check it and print error message, here:
./lib/devres.c:136:__devm_ioremap_resource(

	if (!res || resource_type(res) != IORESOURCE_MEM) {
		dev_err(dev, "invalid resource\n");
		return IOMEM_ERR_PTR(-EINVAL);
Which means you did not test this?  Why not?

But step back, _WHY_ is this needed at all?  How deep are we going to
get with the "devm_platform_get_and_do_this_and_that_and_that" type
functions here?
  the function name seems too long, how can I rename it:)
You show 2 users of this call, and they save what, 1-2 lines of code
here?

What is the real need for this?

thanks,

greg k-h
many thanks for your feedback.

Cai

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Re: [PATCH v2 1/3] driver core: platform: Add the helper function devm_platform_get_and_ioremap_resource_byname()

From: Greg KH <gregkh@linuxfoundation.org>
Date: 2021-09-02 08:25:21

On Thu, Sep 02, 2021 at 04:05:39PM +0800, Cai Huoqing wrote:
On 02 Sep 21 08:52:45, Greg KH wrote:
quoted
On Thu, Sep 02, 2021 at 02:37:00PM +0800, Cai Huoqing wrote:
quoted
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 <redacted>
---
v1->v2: Resend this patch as part of a patch series that uses
	the new function. 

 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 652531f67135..34bb581338d9 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;
You forgot to check the return value of this call :(
devm_ioremap_resource wiil check it and print error message, here:
./lib/devres.c:136:__devm_ioremap_resource(

	if (!res || resource_type(res) != IORESOURCE_MEM) {
		dev_err(dev, "invalid resource\n");
		return IOMEM_ERR_PTR(-EINVAL);
And then you move on and use the resource :(

Please properly test your code.
quoted
Which means you did not test this?  Why not?

But step back, _WHY_ is this needed at all?  How deep are we going to
get with the "devm_platform_get_and_do_this_and_that_and_that" type
functions here?
  the function name seems too long, how can I rename it:)
You have not shown a requirement that this new function is needed at
all.

Why are you making this change?  Why do you want to do this?  What is it
helping out with?

thanks,

greg k-h

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help