linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/5] drivers: new helper for ioremapping memory resources
@ 2020-03-15 14:05 Dejin Zheng
  2020-03-15 14:05 ` [PATCH v3 1/5] drivers: provide devm_platform_get_and_ioremap_resource() Dejin Zheng
                   ` (4 more replies)
  0 siblings, 5 replies; 18+ messages in thread
From: Dejin Zheng @ 2020-03-15 14:05 UTC (permalink / raw)
  To: gregkh, rafael, hminas, mathias.nyman, bgolaszewski, arnd,
	jeffrey.t.kirsher, hdegoede, treding, tglx, tomas.winkler,
	suzuki.poulose, sergei.shtylyov, geert, linux-usb
  Cc: linux-kernel, Dejin Zheng

Since commit "drivers: provide devm_platform_ioremap_resource()",
It was wrap platform_get_resource() and devm_ioremap_resource() as
single helper devm_platform_ioremap_resource(). but now, many drivers
still used platform_get_resource() and devm_ioremap_resource()
together in the kernel tree. The reason can not be replaced is they
still need use the resource variables obtained by platform_get_resource().
so provide this helper.

The first patch in this series adds a wrapper for these two calls and
the other uses it in a driver.

v2 -> v3:
	- rename the function to
	  devm_platform_get_and_ioremap_resource() by Sergei's suggestion.
	- make the last parameter res as optional by Geert's suggestion.
	- Reimplement devm_platform_ioremap_resource by calling
	  devm_platform_get_and_ioremap_resource() by Geert's suggestion.

v1 -> v2:
	- add some real users of this function (Thanks for greg k-h's reminder)

Dejin Zheng (5):
  drivers: provide devm_platform_get_and_ioremap_resource()
  usb: host: xhci-plat: convert to
    devm_platform_get_and_ioremap_resource
  usb: host: hisilicon: convert to
    devm_platform_get_and_ioremap_resource
  usb: dwc2: convert to devm_platform_get_and_ioremap_resource
  driver core: platform: Reimplement devm_platform_ioremap_resource

 drivers/base/platform.c         | 27 +++++++++++++++++++++++----
 drivers/usb/dwc2/platform.c     |  3 +--
 drivers/usb/host/xhci-histb.c   |  3 +--
 drivers/usb/host/xhci-plat.c    |  3 +--
 include/linux/platform_device.h |  3 +++
 5 files changed, 29 insertions(+), 10 deletions(-)

-- 
2.25.0


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

* [PATCH v3 1/5] drivers: provide devm_platform_get_and_ioremap_resource()
  2020-03-15 14:05 [PATCH v3 0/5] drivers: new helper for ioremapping memory resources Dejin Zheng
@ 2020-03-15 14:05 ` Dejin Zheng
  2020-03-17 19:20   ` Greg KH
  2020-03-23 12:44   ` Geert Uytterhoeven
  2020-03-15 14:05 ` [PATCH v3 2/5] usb: host: xhci-plat: convert to devm_platform_get_and_ioremap_resource Dejin Zheng
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 18+ messages in thread
From: Dejin Zheng @ 2020-03-15 14:05 UTC (permalink / raw)
  To: gregkh, rafael, hminas, mathias.nyman, bgolaszewski, arnd,
	jeffrey.t.kirsher, hdegoede, treding, tglx, tomas.winkler,
	suzuki.poulose, sergei.shtylyov, geert, linux-usb
  Cc: linux-kernel, Dejin Zheng

Since commit "drivers: provide devm_platform_ioremap_resource()",
it was wrap platform_get_resource() and devm_ioremap_resource() as
single helper devm_platform_ioremap_resource(). but now, many drivers
still used platform_get_resource() and devm_ioremap_resource()
together in the kernel tree. The reason can not be replaced is they
still need use the resource variables obtained by platform_get_resource().
so provide this helper.

Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Suggested-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
---
v2 -> v3:
	- rename the function to
	  devm_platform_get_and_ioremap_resource() by Sergei's suggestion.
	- make the last parameter res as optional by Geert's suggestion.

v1 -> v2:
	- No change.

 drivers/base/platform.c         | 22 ++++++++++++++++++++++
 include/linux/platform_device.h |  3 +++
 2 files changed, 25 insertions(+)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 7fa654f1288b..9f6a78f79235 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -62,6 +62,28 @@ struct resource *platform_get_resource(struct platform_device *dev,
 EXPORT_SYMBOL_GPL(platform_get_resource);
 
 #ifdef CONFIG_HAS_IOMEM
+/**
+ * devm_platform_get_and_ioremap_resource - 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
+ * @index: resource index
+ * @res: get the resource
+ */
+void __iomem *
+devm_platform_get_and_ioremap_resource(struct platform_device *pdev,
+				unsigned int index, struct resource **res)
+{
+	struct resource *r;
+
+	r = platform_get_resource(pdev, IORESOURCE_MEM, index);
+	if (res)
+		*res = r;
+	return devm_ioremap_resource(&pdev->dev, r);
+}
+EXPORT_SYMBOL_GPL(devm_platform_get_and_ioremap_resource);
+
 /**
  * devm_platform_ioremap_resource - call devm_ioremap_resource() for a platform
  *				    device
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 8e83c6ff140d..8aa6b448450f 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -55,6 +55,9 @@ extern struct device *
 platform_find_device_by_driver(struct device *start,
 			       const struct device_driver *drv);
 extern void __iomem *
+devm_platform_get_and_ioremap_resource(struct platform_device *pdev,
+				unsigned int index, struct resource **res);
+extern void __iomem *
 devm_platform_ioremap_resource(struct platform_device *pdev,
 			       unsigned int index);
 extern void __iomem *
-- 
2.25.0


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

* [PATCH v3 2/5] usb: host: xhci-plat: convert to devm_platform_get_and_ioremap_resource
  2020-03-15 14:05 [PATCH v3 0/5] drivers: new helper for ioremapping memory resources Dejin Zheng
  2020-03-15 14:05 ` [PATCH v3 1/5] drivers: provide devm_platform_get_and_ioremap_resource() Dejin Zheng
@ 2020-03-15 14:05 ` Dejin Zheng
  2020-03-18 11:33   ` Mathias Nyman
  2020-03-23 12:45   ` Geert Uytterhoeven
  2020-03-15 14:05 ` [PATCH v3 3/5] usb: host: hisilicon: " Dejin Zheng
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 18+ messages in thread
From: Dejin Zheng @ 2020-03-15 14:05 UTC (permalink / raw)
  To: gregkh, rafael, hminas, mathias.nyman, bgolaszewski, arnd,
	jeffrey.t.kirsher, hdegoede, treding, tglx, tomas.winkler,
	suzuki.poulose, sergei.shtylyov, geert, linux-usb
  Cc: linux-kernel, Dejin Zheng

Use devm_platform_get_and_ioremap_resource() to simplify code, which
contains platform_get_resource() and devm_ioremap_resource(), it also
get the resource for use by the following code.

Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
---
v2 -> v3:
	- call the rename function devm_platform_get_and_ioremap_resource()

v1 -> v2:
	- add this patch for add some real users of this function. 
 
 drivers/usb/host/xhci-plat.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index d90cd5ec09cf..dcc0bfe04c43 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -219,8 +219,7 @@ static int xhci_plat_probe(struct platform_device *pdev)
 		goto disable_runtime;
 	}
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	hcd->regs = devm_ioremap_resource(&pdev->dev, res);
+	hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
 	if (IS_ERR(hcd->regs)) {
 		ret = PTR_ERR(hcd->regs);
 		goto put_hcd;
-- 
2.25.0


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

* [PATCH v3 3/5] usb: host: hisilicon: convert to devm_platform_get_and_ioremap_resource
  2020-03-15 14:05 [PATCH v3 0/5] drivers: new helper for ioremapping memory resources Dejin Zheng
  2020-03-15 14:05 ` [PATCH v3 1/5] drivers: provide devm_platform_get_and_ioremap_resource() Dejin Zheng
  2020-03-15 14:05 ` [PATCH v3 2/5] usb: host: xhci-plat: convert to devm_platform_get_and_ioremap_resource Dejin Zheng
@ 2020-03-15 14:05 ` Dejin Zheng
  2020-03-18 11:35   ` Mathias Nyman
  2020-03-23 12:45   ` Geert Uytterhoeven
  2020-03-15 14:05 ` [PATCH v3 4/5] usb: dwc2: " Dejin Zheng
  2020-03-15 14:05 ` [PATCH v3 5/5] driver core: platform: Reimplement devm_platform_ioremap_resource Dejin Zheng
  4 siblings, 2 replies; 18+ messages in thread
From: Dejin Zheng @ 2020-03-15 14:05 UTC (permalink / raw)
  To: gregkh, rafael, hminas, mathias.nyman, bgolaszewski, arnd,
	jeffrey.t.kirsher, hdegoede, treding, tglx, tomas.winkler,
	suzuki.poulose, sergei.shtylyov, geert, linux-usb
  Cc: linux-kernel, Dejin Zheng

Use devm_platform_get_and_ioremap_resource() to simplify code, which
contains platform_get_resource() and devm_ioremap_resource(), it also
get the resource for use by the following code.

Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
---
v2 -> v3:
	- call the rename function devm_platform_get_and_ioremap_resource()

v1 -> v2:
	- add this patch for add some real users of this function. 
 
 drivers/usb/host/xhci-histb.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci-histb.c b/drivers/usb/host/xhci-histb.c
index 3c4abb5a1c3f..5546e7e013a8 100644
--- a/drivers/usb/host/xhci-histb.c
+++ b/drivers/usb/host/xhci-histb.c
@@ -219,8 +219,7 @@ static int xhci_histb_probe(struct platform_device *pdev)
 	if (irq < 0)
 		return irq;
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	histb->ctrl = devm_ioremap_resource(&pdev->dev, res);
+	histb->ctrl = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
 	if (IS_ERR(histb->ctrl))
 		return PTR_ERR(histb->ctrl);
 
-- 
2.25.0


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

* [PATCH v3 4/5] usb: dwc2: convert to devm_platform_get_and_ioremap_resource
  2020-03-15 14:05 [PATCH v3 0/5] drivers: new helper for ioremapping memory resources Dejin Zheng
                   ` (2 preceding siblings ...)
  2020-03-15 14:05 ` [PATCH v3 3/5] usb: host: hisilicon: " Dejin Zheng
@ 2020-03-15 14:05 ` Dejin Zheng
  2020-03-18 10:40   ` Minas Harutyunyan
  2020-03-23 12:47   ` Geert Uytterhoeven
  2020-03-15 14:05 ` [PATCH v3 5/5] driver core: platform: Reimplement devm_platform_ioremap_resource Dejin Zheng
  4 siblings, 2 replies; 18+ messages in thread
From: Dejin Zheng @ 2020-03-15 14:05 UTC (permalink / raw)
  To: gregkh, rafael, hminas, mathias.nyman, bgolaszewski, arnd,
	jeffrey.t.kirsher, hdegoede, treding, tglx, tomas.winkler,
	suzuki.poulose, sergei.shtylyov, geert, linux-usb
  Cc: linux-kernel, Dejin Zheng

Use devm_platform_get_and_ioremap_resource() to simplify code, which
contains platform_get_resource() and devm_ioremap_resource(), it also
get the resource for use by the following code.

Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
---
v2 -> v3:
	- call the rename function devm_platform_get_and_ioremap_resource()

v1 -> v2:
	- add this patch for add some real users of this function. 
 
 drivers/usb/dwc2/platform.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index 3c6ce09a6db5..8a68e89749d2 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -392,8 +392,7 @@ static int dwc2_driver_probe(struct platform_device *dev)
 		return retval;
 	}
 
-	res = platform_get_resource(dev, IORESOURCE_MEM, 0);
-	hsotg->regs = devm_ioremap_resource(&dev->dev, res);
+	hsotg->regs = devm_platform_get_and_ioremap_resource(dev, 0, &res);
 	if (IS_ERR(hsotg->regs))
 		return PTR_ERR(hsotg->regs);
 
-- 
2.25.0


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

* [PATCH v3 5/5] driver core: platform: Reimplement devm_platform_ioremap_resource
  2020-03-15 14:05 [PATCH v3 0/5] drivers: new helper for ioremapping memory resources Dejin Zheng
                   ` (3 preceding siblings ...)
  2020-03-15 14:05 ` [PATCH v3 4/5] usb: dwc2: " Dejin Zheng
@ 2020-03-15 14:05 ` Dejin Zheng
  2020-03-23 12:47   ` Geert Uytterhoeven
  4 siblings, 1 reply; 18+ messages in thread
From: Dejin Zheng @ 2020-03-15 14:05 UTC (permalink / raw)
  To: gregkh, rafael, hminas, mathias.nyman, bgolaszewski, arnd,
	jeffrey.t.kirsher, hdegoede, treding, tglx, tomas.winkler,
	suzuki.poulose, sergei.shtylyov, geert, linux-usb
  Cc: linux-kernel, Dejin Zheng

Reimplement devm_platform_ioremap_resource() by calling
devm_platform_ioremap_and_get_resource() with res = NULL for
simplify the code.

Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
---
v2 -> v3:
	- add this patch to simplify the code by Geert's suggestion.

 drivers/base/platform.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 9f6a78f79235..b83b789c8e34 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -95,10 +95,7 @@ EXPORT_SYMBOL_GPL(devm_platform_get_and_ioremap_resource);
 void __iomem *devm_platform_ioremap_resource(struct platform_device *pdev,
 					     unsigned int index)
 {
-	struct resource *res;
-
-	res = platform_get_resource(pdev, IORESOURCE_MEM, index);
-	return devm_ioremap_resource(&pdev->dev, res);
+	return devm_platform_get_and_ioremap_resource(pdev, index, NULL);
 }
 EXPORT_SYMBOL_GPL(devm_platform_ioremap_resource);
 
-- 
2.25.0


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

* Re: [PATCH v3 1/5] drivers: provide devm_platform_get_and_ioremap_resource()
  2020-03-15 14:05 ` [PATCH v3 1/5] drivers: provide devm_platform_get_and_ioremap_resource() Dejin Zheng
@ 2020-03-17 19:20   ` Greg KH
  2020-03-17 19:35     ` Geert Uytterhoeven
  2020-03-23 12:44   ` Geert Uytterhoeven
  1 sibling, 1 reply; 18+ messages in thread
From: Greg KH @ 2020-03-17 19:20 UTC (permalink / raw)
  To: Dejin Zheng
  Cc: rafael, hminas, mathias.nyman, bgolaszewski, arnd,
	jeffrey.t.kirsher, hdegoede, treding, tglx, tomas.winkler,
	suzuki.poulose, sergei.shtylyov, geert, linux-usb, linux-kernel

On Sun, Mar 15, 2020 at 10:05:21PM +0800, Dejin Zheng wrote:
> Since commit "drivers: provide devm_platform_ioremap_resource()",
> it was wrap platform_get_resource() and devm_ioremap_resource() as
> single helper devm_platform_ioremap_resource(). but now, many drivers
> still used platform_get_resource() and devm_ioremap_resource()
> together in the kernel tree. The reason can not be replaced is they
> still need use the resource variables obtained by platform_get_resource().
> so provide this helper.
> 
> Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
> Suggested-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
> Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
> ---
> v2 -> v3:
> 	- rename the function to
> 	  devm_platform_get_and_ioremap_resource() by Sergei's suggestion.
> 	- make the last parameter res as optional by Geert's suggestion.
> 
> v1 -> v2:
> 	- No change.
> 
>  drivers/base/platform.c         | 22 ++++++++++++++++++++++
>  include/linux/platform_device.h |  3 +++
>  2 files changed, 25 insertions(+)
> 
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index 7fa654f1288b..9f6a78f79235 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -62,6 +62,28 @@ struct resource *platform_get_resource(struct platform_device *dev,
>  EXPORT_SYMBOL_GPL(platform_get_resource);
>  
>  #ifdef CONFIG_HAS_IOMEM
> +/**
> + * devm_platform_get_and_ioremap_resource - 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
> + * @index: resource index
> + * @res: get the resource
> + */
> +void __iomem *
> +devm_platform_get_and_ioremap_resource(struct platform_device *pdev,
> +				unsigned int index, struct resource **res)
> +{
> +	struct resource *r;
> +
> +	r = platform_get_resource(pdev, IORESOURCE_MEM, index);
> +	if (res)
> +		*res = r;

What happens if that call fails?  Shouldn't that be checked?

thanks,

greg k-h

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

* Re: [PATCH v3 1/5] drivers: provide devm_platform_get_and_ioremap_resource()
  2020-03-17 19:20   ` Greg KH
@ 2020-03-17 19:35     ` Geert Uytterhoeven
  2020-03-18 10:10       ` Greg KH
  0 siblings, 1 reply; 18+ messages in thread
From: Geert Uytterhoeven @ 2020-03-17 19:35 UTC (permalink / raw)
  To: Greg KH
  Cc: Dejin Zheng, Rafael J. Wysocki, Minas Harutyunyan, Mathias Nyman,
	Bartosz Golaszewski, Arnd Bergmann, Jeff Kirsher, Hans de Goede,
	Thierry Reding, Thomas Gleixner, Winkler, Tomas,
	Suzuki K Poulose, Sergei Shtylyov, USB list,
	Linux Kernel Mailing List

Hi Greg,

On Tue, Mar 17, 2020 at 8:20 PM Greg KH <gregkh@linuxfoundation.org> wrote:
> On Sun, Mar 15, 2020 at 10:05:21PM +0800, Dejin Zheng wrote:
> > Since commit "drivers: provide devm_platform_ioremap_resource()",
> > it was wrap platform_get_resource() and devm_ioremap_resource() as
> > single helper devm_platform_ioremap_resource(). but now, many drivers
> > still used platform_get_resource() and devm_ioremap_resource()
> > together in the kernel tree. The reason can not be replaced is they
> > still need use the resource variables obtained by platform_get_resource().
> > so provide this helper.
> >
> > Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
> > Suggested-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
> > Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
> > ---
> > v2 -> v3:
> >       - rename the function to
> >         devm_platform_get_and_ioremap_resource() by Sergei's suggestion.
> >       - make the last parameter res as optional by Geert's suggestion.
> >
> > v1 -> v2:
> >       - No change.
> >
> >  drivers/base/platform.c         | 22 ++++++++++++++++++++++
> >  include/linux/platform_device.h |  3 +++
> >  2 files changed, 25 insertions(+)
> >
> > diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> > index 7fa654f1288b..9f6a78f79235 100644
> > --- a/drivers/base/platform.c
> > +++ b/drivers/base/platform.c
> > @@ -62,6 +62,28 @@ struct resource *platform_get_resource(struct platform_device *dev,
> >  EXPORT_SYMBOL_GPL(platform_get_resource);
> >
> >  #ifdef CONFIG_HAS_IOMEM
> > +/**
> > + * devm_platform_get_and_ioremap_resource - 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
> > + * @index: resource index
> > + * @res: get the resource
> > + */
> > +void __iomem *
> > +devm_platform_get_and_ioremap_resource(struct platform_device *pdev,
> > +                             unsigned int index, struct resource **res)
> > +{
> > +     struct resource *r;
> > +
> > +     r = platform_get_resource(pdev, IORESOURCE_MEM, index);
> > +     if (res)
> > +             *res = r;
>
> What happens if that call fails?  Shouldn't that be checked?

Then devm_ioremap_resource() will print an error message, and return
an error.
It's designed to be pipelined that way, so you have to check for an error
only once.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH v3 1/5] drivers: provide devm_platform_get_and_ioremap_resource()
  2020-03-17 19:35     ` Geert Uytterhoeven
@ 2020-03-18 10:10       ` Greg KH
  2020-03-20 14:06         ` Dejin Zheng
  0 siblings, 1 reply; 18+ messages in thread
From: Greg KH @ 2020-03-18 10:10 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Dejin Zheng, Rafael J. Wysocki, Minas Harutyunyan, Mathias Nyman,
	Bartosz Golaszewski, Arnd Bergmann, Jeff Kirsher, Hans de Goede,
	Thierry Reding, Thomas Gleixner, Winkler, Tomas,
	Suzuki K Poulose, Sergei Shtylyov, USB list,
	Linux Kernel Mailing List

On Tue, Mar 17, 2020 at 08:35:16PM +0100, Geert Uytterhoeven wrote:
> Hi Greg,
> 
> On Tue, Mar 17, 2020 at 8:20 PM Greg KH <gregkh@linuxfoundation.org> wrote:
> > On Sun, Mar 15, 2020 at 10:05:21PM +0800, Dejin Zheng wrote:
> > > Since commit "drivers: provide devm_platform_ioremap_resource()",
> > > it was wrap platform_get_resource() and devm_ioremap_resource() as
> > > single helper devm_platform_ioremap_resource(). but now, many drivers
> > > still used platform_get_resource() and devm_ioremap_resource()
> > > together in the kernel tree. The reason can not be replaced is they
> > > still need use the resource variables obtained by platform_get_resource().
> > > so provide this helper.
> > >
> > > Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
> > > Suggested-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
> > > Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
> > > ---
> > > v2 -> v3:
> > >       - rename the function to
> > >         devm_platform_get_and_ioremap_resource() by Sergei's suggestion.
> > >       - make the last parameter res as optional by Geert's suggestion.
> > >
> > > v1 -> v2:
> > >       - No change.
> > >
> > >  drivers/base/platform.c         | 22 ++++++++++++++++++++++
> > >  include/linux/platform_device.h |  3 +++
> > >  2 files changed, 25 insertions(+)
> > >
> > > diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> > > index 7fa654f1288b..9f6a78f79235 100644
> > > --- a/drivers/base/platform.c
> > > +++ b/drivers/base/platform.c
> > > @@ -62,6 +62,28 @@ struct resource *platform_get_resource(struct platform_device *dev,
> > >  EXPORT_SYMBOL_GPL(platform_get_resource);
> > >
> > >  #ifdef CONFIG_HAS_IOMEM
> > > +/**
> > > + * devm_platform_get_and_ioremap_resource - 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
> > > + * @index: resource index
> > > + * @res: get the resource
> > > + */
> > > +void __iomem *
> > > +devm_platform_get_and_ioremap_resource(struct platform_device *pdev,
> > > +                             unsigned int index, struct resource **res)
> > > +{
> > > +     struct resource *r;
> > > +
> > > +     r = platform_get_resource(pdev, IORESOURCE_MEM, index);
> > > +     if (res)
> > > +             *res = r;
> >
> > What happens if that call fails?  Shouldn't that be checked?
> 
> Then devm_ioremap_resource() will print an error message, and return
> an error.
> It's designed to be pipelined that way, so you have to check for an error
> only once.

Ok, thanks.  Can I get an ack/reviewed-by for this series then?

thanks,

greg k-h

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

* Re: [PATCH v3 4/5] usb: dwc2: convert to devm_platform_get_and_ioremap_resource
  2020-03-15 14:05 ` [PATCH v3 4/5] usb: dwc2: " Dejin Zheng
@ 2020-03-18 10:40   ` Minas Harutyunyan
  2020-03-23 12:47   ` Geert Uytterhoeven
  1 sibling, 0 replies; 18+ messages in thread
From: Minas Harutyunyan @ 2020-03-18 10:40 UTC (permalink / raw)
  To: Dejin Zheng, gregkh, rafael, mathias.nyman, bgolaszewski, arnd,
	jeffrey.t.kirsher, hdegoede, treding, tglx, tomas.winkler,
	suzuki.poulose, sergei.shtylyov, geert, linux-usb
  Cc: linux-kernel



On 3/15/2020 6:05 PM, Dejin Zheng wrote:
> Use devm_platform_get_and_ioremap_resource() to simplify code, which
> contains platform_get_resource() and devm_ioremap_resource(), it also
> get the resource for use by the following code.
> 
> Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>

Acked-by: Minas Harutyunyan <hminas@synopsys.com>

> ---
> v2 -> v3:
> 	- call the rename function devm_platform_get_and_ioremap_resource()
> 
> v1 -> v2:
> 	- add this patch for add some real users of this function.
>   
>   drivers/usb/dwc2/platform.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
> index 3c6ce09a6db5..8a68e89749d2 100644
> --- a/drivers/usb/dwc2/platform.c
> +++ b/drivers/usb/dwc2/platform.c
> @@ -392,8 +392,7 @@ static int dwc2_driver_probe(struct platform_device *dev)
>   		return retval;
>   	}
>   
> -	res = platform_get_resource(dev, IORESOURCE_MEM, 0);
> -	hsotg->regs = devm_ioremap_resource(&dev->dev, res);
> +	hsotg->regs = devm_platform_get_and_ioremap_resource(dev, 0, &res);
>   	if (IS_ERR(hsotg->regs))
>   		return PTR_ERR(hsotg->regs);
>   
> 

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

* Re: [PATCH v3 2/5] usb: host: xhci-plat: convert to devm_platform_get_and_ioremap_resource
  2020-03-15 14:05 ` [PATCH v3 2/5] usb: host: xhci-plat: convert to devm_platform_get_and_ioremap_resource Dejin Zheng
@ 2020-03-18 11:33   ` Mathias Nyman
  2020-03-23 12:45   ` Geert Uytterhoeven
  1 sibling, 0 replies; 18+ messages in thread
From: Mathias Nyman @ 2020-03-18 11:33 UTC (permalink / raw)
  To: Dejin Zheng, gregkh, rafael, hminas, mathias.nyman, bgolaszewski,
	arnd, jeffrey.t.kirsher, hdegoede, treding, tglx, tomas.winkler,
	suzuki.poulose, sergei.shtylyov, geert, linux-usb
  Cc: linux-kernel

On 15.3.2020 16.05, Dejin Zheng wrote:
> Use devm_platform_get_and_ioremap_resource() to simplify code, which
> contains platform_get_resource() and devm_ioremap_resource(), it also
> get the resource for use by the following code.
> 
> Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>

Acked-by: Mathias Nyman <mathias.nyman@linux.intel.com>

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

* Re: [PATCH v3 3/5] usb: host: hisilicon: convert to devm_platform_get_and_ioremap_resource
  2020-03-15 14:05 ` [PATCH v3 3/5] usb: host: hisilicon: " Dejin Zheng
@ 2020-03-18 11:35   ` Mathias Nyman
  2020-03-23 12:45   ` Geert Uytterhoeven
  1 sibling, 0 replies; 18+ messages in thread
From: Mathias Nyman @ 2020-03-18 11:35 UTC (permalink / raw)
  To: Dejin Zheng, gregkh, rafael, hminas, mathias.nyman, bgolaszewski,
	arnd, jeffrey.t.kirsher, hdegoede, treding, tglx, tomas.winkler,
	suzuki.poulose, sergei.shtylyov, geert, linux-usb
  Cc: linux-kernel

On 15.3.2020 16.05, Dejin Zheng wrote:
> Use devm_platform_get_and_ioremap_resource() to simplify code, which
> contains platform_get_resource() and devm_ioremap_resource(), it also
> get the resource for use by the following code.
> 
> Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
> ---

Acked-by: Mathias Nyman <mathias.nyman@linux.intel.com>


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

* Re: [PATCH v3 1/5] drivers: provide devm_platform_get_and_ioremap_resource()
  2020-03-18 10:10       ` Greg KH
@ 2020-03-20 14:06         ` Dejin Zheng
  0 siblings, 0 replies; 18+ messages in thread
From: Dejin Zheng @ 2020-03-20 14:06 UTC (permalink / raw)
  To: Greg KH, Mathias Nyman, Geert Uytterhoeven, Minas Harutyunyan
  Cc: Rafael J. Wysocki, Bartosz Golaszewski, Arnd Bergmann,
	Jeff Kirsher, Hans de Goede, Thierry Reding, Thomas Gleixner,
	Winkler, Tomas, Suzuki K Poulose, Sergei Shtylyov, USB list,
	Linux Kernel Mailing List

On Wed, Mar 18, 2020 at 11:10:10AM +0100, Greg KH wrote:
> On Tue, Mar 17, 2020 at 08:35:16PM +0100, Geert Uytterhoeven wrote:
> > Hi Greg,
> > 
> > On Tue, Mar 17, 2020 at 8:20 PM Greg KH <gregkh@linuxfoundation.org> wrote:
> > > On Sun, Mar 15, 2020 at 10:05:21PM +0800, Dejin Zheng wrote:
> > > > Since commit "drivers: provide devm_platform_ioremap_resource()",
> > > > it was wrap platform_get_resource() and devm_ioremap_resource() as
> > > > single helper devm_platform_ioremap_resource(). but now, many drivers
> > > > still used platform_get_resource() and devm_ioremap_resource()
> > > > together in the kernel tree. The reason can not be replaced is they
> > > > still need use the resource variables obtained by platform_get_resource().
> > > > so provide this helper.
> > > >
> > > > Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
> > > > Suggested-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
> > > > Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
> > > > ---
> > > > v2 -> v3:
> > > >       - rename the function to
> > > >         devm_platform_get_and_ioremap_resource() by Sergei's suggestion.
> > > >       - make the last parameter res as optional by Geert's suggestion.
> > > >
> > > > v1 -> v2:
> > > >       - No change.
> > > >
> > > >  drivers/base/platform.c         | 22 ++++++++++++++++++++++
> > > >  include/linux/platform_device.h |  3 +++
> > > >  2 files changed, 25 insertions(+)
> > > >
> > > > diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> > > > index 7fa654f1288b..9f6a78f79235 100644
> > > > --- a/drivers/base/platform.c
> > > > +++ b/drivers/base/platform.c
> > > > @@ -62,6 +62,28 @@ struct resource *platform_get_resource(struct platform_device *dev,
> > > >  EXPORT_SYMBOL_GPL(platform_get_resource);
> > > >
> > > >  #ifdef CONFIG_HAS_IOMEM
> > > > +/**
> > > > + * devm_platform_get_and_ioremap_resource - 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
> > > > + * @index: resource index
> > > > + * @res: get the resource
> > > > + */
> > > > +void __iomem *
> > > > +devm_platform_get_and_ioremap_resource(struct platform_device *pdev,
> > > > +                             unsigned int index, struct resource **res)
> > > > +{
> > > > +     struct resource *r;
> > > > +
> > > > +     r = platform_get_resource(pdev, IORESOURCE_MEM, index);
> > > > +     if (res)
> > > > +             *res = r;
> > >
> > > What happens if that call fails?  Shouldn't that be checked?
> > 
> > Then devm_ioremap_resource() will print an error message, and return
> > an error.
> > It's designed to be pipelined that way, so you have to check for an error
> > only once.
> 
> Ok, thanks.  Can I get an ack/reviewed-by for this series then?
> 
> thanks,
> 
> greg k-h

Hi Geert:

Could you help me review these patches if you have free time? Your comments and
suggestions will be of great help to me. It is important to me and thanks
again for your help.

Hi Greg, Mathias and Minas:

Thank you very much for taking your time to help me review my code.

BR,
Dejin


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

* Re: [PATCH v3 1/5] drivers: provide devm_platform_get_and_ioremap_resource()
  2020-03-15 14:05 ` [PATCH v3 1/5] drivers: provide devm_platform_get_and_ioremap_resource() Dejin Zheng
  2020-03-17 19:20   ` Greg KH
@ 2020-03-23 12:44   ` Geert Uytterhoeven
  1 sibling, 0 replies; 18+ messages in thread
From: Geert Uytterhoeven @ 2020-03-23 12:44 UTC (permalink / raw)
  To: Dejin Zheng
  Cc: Greg KH, Rafael J. Wysocki, Minas Harutyunyan, Mathias Nyman,
	Bartosz Golaszewski, Arnd Bergmann, Jeff Kirsher, Hans de Goede,
	Thierry Reding, Thomas Gleixner, Winkler, Tomas,
	Suzuki K Poulose, Sergei Shtylyov, USB list,
	Linux Kernel Mailing List

Hi Dejin,

On Sun, Mar 15, 2020 at 3:05 PM Dejin Zheng <zhengdejin5@gmail.com> wrote:
> Since commit "drivers: provide devm_platform_ioremap_resource()",
> it was wrap platform_get_resource() and devm_ioremap_resource() as
> single helper devm_platform_ioremap_resource(). but now, many drivers
> still used platform_get_resource() and devm_ioremap_resource()
> together in the kernel tree. The reason can not be replaced is they
> still need use the resource variables obtained by platform_get_resource().
> so provide this helper.
>
> Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
> Suggested-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
> Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>

Thanks for your patch!

> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -62,6 +62,28 @@ struct resource *platform_get_resource(struct platform_device *dev,
>  EXPORT_SYMBOL_GPL(platform_get_resource);
>
>  #ifdef CONFIG_HAS_IOMEM
> +/**
> + * devm_platform_get_and_ioremap_resource - 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
> + * @index: resource index
> + * @res: get the resource

Optional output parameter to store a pointer to the obtained resource.

With the above changed:

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

> + */
> +void __iomem *
> +devm_platform_get_and_ioremap_resource(struct platform_device *pdev,
> +                               unsigned int index, struct resource **res)
> +{
> +       struct resource *r;
> +
> +       r = platform_get_resource(pdev, IORESOURCE_MEM, index);
> +       if (res)
> +               *res = r;
> +       return devm_ioremap_resource(&pdev->dev, r);
> +}
> +EXPORT_SYMBOL_GPL(devm_platform_get_and_ioremap_resource);

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH v3 2/5] usb: host: xhci-plat: convert to devm_platform_get_and_ioremap_resource
  2020-03-15 14:05 ` [PATCH v3 2/5] usb: host: xhci-plat: convert to devm_platform_get_and_ioremap_resource Dejin Zheng
  2020-03-18 11:33   ` Mathias Nyman
@ 2020-03-23 12:45   ` Geert Uytterhoeven
  1 sibling, 0 replies; 18+ messages in thread
From: Geert Uytterhoeven @ 2020-03-23 12:45 UTC (permalink / raw)
  To: Dejin Zheng
  Cc: Greg KH, Rafael J. Wysocki, Minas Harutyunyan, Mathias Nyman,
	Bartosz Golaszewski, Arnd Bergmann, Jeff Kirsher, Hans de Goede,
	Thierry Reding, Thomas Gleixner, Winkler, Tomas,
	Suzuki K Poulose, Sergei Shtylyov, USB list,
	Linux Kernel Mailing List

On Sun, Mar 15, 2020 at 3:05 PM Dejin Zheng <zhengdejin5@gmail.com> wrote:
> Use devm_platform_get_and_ioremap_resource() to simplify code, which
> contains platform_get_resource() and devm_ioremap_resource(), it also
> get the resource for use by the following code.
>
> Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH v3 3/5] usb: host: hisilicon: convert to devm_platform_get_and_ioremap_resource
  2020-03-15 14:05 ` [PATCH v3 3/5] usb: host: hisilicon: " Dejin Zheng
  2020-03-18 11:35   ` Mathias Nyman
@ 2020-03-23 12:45   ` Geert Uytterhoeven
  1 sibling, 0 replies; 18+ messages in thread
From: Geert Uytterhoeven @ 2020-03-23 12:45 UTC (permalink / raw)
  To: Dejin Zheng
  Cc: Greg KH, Rafael J. Wysocki, Minas Harutyunyan, Mathias Nyman,
	Bartosz Golaszewski, Arnd Bergmann, Jeff Kirsher, Hans de Goede,
	Thierry Reding, Thomas Gleixner, Winkler, Tomas,
	Suzuki K Poulose, Sergei Shtylyov, USB list,
	Linux Kernel Mailing List

On Sun, Mar 15, 2020 at 3:05 PM Dejin Zheng <zhengdejin5@gmail.com> wrote:
> Use devm_platform_get_and_ioremap_resource() to simplify code, which
> contains platform_get_resource() and devm_ioremap_resource(), it also
> get the resource for use by the following code.
>
> Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH v3 4/5] usb: dwc2: convert to devm_platform_get_and_ioremap_resource
  2020-03-15 14:05 ` [PATCH v3 4/5] usb: dwc2: " Dejin Zheng
  2020-03-18 10:40   ` Minas Harutyunyan
@ 2020-03-23 12:47   ` Geert Uytterhoeven
  1 sibling, 0 replies; 18+ messages in thread
From: Geert Uytterhoeven @ 2020-03-23 12:47 UTC (permalink / raw)
  To: Dejin Zheng
  Cc: Greg KH, Rafael J. Wysocki, Minas Harutyunyan, Mathias Nyman,
	Bartosz Golaszewski, Arnd Bergmann, Jeff Kirsher, Hans de Goede,
	Thierry Reding, Thomas Gleixner, Winkler, Tomas,
	Suzuki K Poulose, Sergei Shtylyov, USB list,
	Linux Kernel Mailing List

On Sun, Mar 15, 2020 at 3:05 PM Dejin Zheng <zhengdejin5@gmail.com> wrote:
> Use devm_platform_get_and_ioremap_resource() to simplify code, which
> contains platform_get_resource() and devm_ioremap_resource(), it also
> get the resource for use by the following code.
>
> Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH v3 5/5] driver core: platform: Reimplement devm_platform_ioremap_resource
  2020-03-15 14:05 ` [PATCH v3 5/5] driver core: platform: Reimplement devm_platform_ioremap_resource Dejin Zheng
@ 2020-03-23 12:47   ` Geert Uytterhoeven
  0 siblings, 0 replies; 18+ messages in thread
From: Geert Uytterhoeven @ 2020-03-23 12:47 UTC (permalink / raw)
  To: Dejin Zheng
  Cc: Greg KH, Rafael J. Wysocki, Minas Harutyunyan, Mathias Nyman,
	Bartosz Golaszewski, Arnd Bergmann, Jeff Kirsher, Hans de Goede,
	Thierry Reding, Thomas Gleixner, Winkler, Tomas,
	Suzuki K Poulose, Sergei Shtylyov, USB list,
	Linux Kernel Mailing List

On Sun, Mar 15, 2020 at 3:06 PM Dejin Zheng <zhengdejin5@gmail.com> wrote:
> Reimplement devm_platform_ioremap_resource() by calling
> devm_platform_ioremap_and_get_resource() with res = NULL for

s/for/to/

> simplify the code.
>
> Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
> Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

end of thread, other threads:[~2020-03-23 12:48 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-15 14:05 [PATCH v3 0/5] drivers: new helper for ioremapping memory resources Dejin Zheng
2020-03-15 14:05 ` [PATCH v3 1/5] drivers: provide devm_platform_get_and_ioremap_resource() Dejin Zheng
2020-03-17 19:20   ` Greg KH
2020-03-17 19:35     ` Geert Uytterhoeven
2020-03-18 10:10       ` Greg KH
2020-03-20 14:06         ` Dejin Zheng
2020-03-23 12:44   ` Geert Uytterhoeven
2020-03-15 14:05 ` [PATCH v3 2/5] usb: host: xhci-plat: convert to devm_platform_get_and_ioremap_resource Dejin Zheng
2020-03-18 11:33   ` Mathias Nyman
2020-03-23 12:45   ` Geert Uytterhoeven
2020-03-15 14:05 ` [PATCH v3 3/5] usb: host: hisilicon: " Dejin Zheng
2020-03-18 11:35   ` Mathias Nyman
2020-03-23 12:45   ` Geert Uytterhoeven
2020-03-15 14:05 ` [PATCH v3 4/5] usb: dwc2: " Dejin Zheng
2020-03-18 10:40   ` Minas Harutyunyan
2020-03-23 12:47   ` Geert Uytterhoeven
2020-03-15 14:05 ` [PATCH v3 5/5] driver core: platform: Reimplement devm_platform_ioremap_resource Dejin Zheng
2020-03-23 12:47   ` Geert Uytterhoeven

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).