2012-10-05 16:23:57

by Florian Fainelli

[permalink] [raw]
Subject: [PATCH 31/32] USB: EHCI: make ehci-platform use devm_{ioremap,request_mem_region} helpers

This patch changes the ehci-platform driver to use the device managed helper
functions for requesting memory region and ioremapping memory resources.
As a result the error path in the probe function is simplified, and the
platform driver remove callback does not longer need to release and iounmap
memory resources.

Signed-off-by: Florian Fainelli <[email protected]>
---
drivers/usb/host/ehci-platform.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
index 3cb0b1b..ebe92cf 100644
--- a/drivers/usb/host/ehci-platform.c
+++ b/drivers/usb/host/ehci-platform.c
@@ -123,29 +123,27 @@ static int __devinit ehci_platform_probe(struct platform_device *dev)
hcd->rsrc_start = res_mem->start;
hcd->rsrc_len = resource_size(res_mem);

- if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
+ if (!devm_request_mem_region(&dev->dev, hcd->rsrc_start,
+ hcd->rsrc_len, hcd_name)) {
dev_err(&dev->dev, "controller already in use");
err = -EBUSY;
goto err_put_hcd;
}

- hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
+ hcd->regs = devm_ioremap_nocache(&dev->dev, hcd->rsrc_start,
+ hcd->rsrc_len);
if (!hcd->regs) {
err = -ENOMEM;
- goto err_release_region;
+ goto err_put_hcd;
}
err = usb_add_hcd(hcd, irq, IRQF_SHARED);
if (err)
- goto err_iounmap;
+ goto err_put_hcd;

platform_set_drvdata(dev, hcd);

return err;

-err_iounmap:
- iounmap(hcd->regs);
-err_release_region:
- release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
err_put_hcd:
usb_put_hcd(hcd);
err_power:
@@ -161,8 +159,6 @@ static int __devexit ehci_platform_remove(struct platform_device *dev)
struct usb_ehci_pdata *pdata = dev->dev.platform_data;

usb_remove_hcd(hcd);
- iounmap(hcd->regs);
- release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
usb_put_hcd(hcd);
platform_set_drvdata(dev, NULL);

--
1.7.9.5


2012-10-05 16:29:46

by Florian Fainelli

[permalink] [raw]
Subject: Re: [PATCH 31/32] USB: EHCI: make ehci-platform use devm_{ioremap,request_mem_region} helpers

FlorianOn Friday 05 October 2012 18:21:03 Fainelli wrote:
> This patch changes the ehci-platform driver to use the device managed helper
> functions for requesting memory region and ioremapping memory resources.
> As a result the error path in the probe function is simplified, and the
> platform driver remove callback does not longer need to release and iounmap
> memory resources.

I just realized that I could use devm_request_and_ioremap() instead of these
two calls. Alan, do you mind dropping these last two patches of my serie
and me sending an updated version of both of these patches?

Thanks!

>
> Signed-off-by: Florian Fainelli <[email protected]>
> ---
> drivers/usb/host/ehci-platform.c | 16 ++++++----------
> 1 file changed, 6 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
> index 3cb0b1b..ebe92cf 100644
> --- a/drivers/usb/host/ehci-platform.c
> +++ b/drivers/usb/host/ehci-platform.c
> @@ -123,29 +123,27 @@ static int __devinit ehci_platform_probe(struct platform_device *dev)
> hcd->rsrc_start = res_mem->start;
> hcd->rsrc_len = resource_size(res_mem);
>
> - if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
> + if (!devm_request_mem_region(&dev->dev, hcd->rsrc_start,
> + hcd->rsrc_len, hcd_name)) {
> dev_err(&dev->dev, "controller already in use");
> err = -EBUSY;
> goto err_put_hcd;
> }
>
> - hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
> + hcd->regs = devm_ioremap_nocache(&dev->dev, hcd->rsrc_start,
> + hcd->rsrc_len);
> if (!hcd->regs) {
> err = -ENOMEM;
> - goto err_release_region;
> + goto err_put_hcd;
> }
> err = usb_add_hcd(hcd, irq, IRQF_SHARED);
> if (err)
> - goto err_iounmap;
> + goto err_put_hcd;
>
> platform_set_drvdata(dev, hcd);
>
> return err;
>
> -err_iounmap:
> - iounmap(hcd->regs);
> -err_release_region:
> - release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
> err_put_hcd:
> usb_put_hcd(hcd);
> err_power:
> @@ -161,8 +159,6 @@ static int __devexit ehci_platform_remove(struct platform_device *dev)
> struct usb_ehci_pdata *pdata = dev->dev.platform_data;
>
> usb_remove_hcd(hcd);
> - iounmap(hcd->regs);
> - release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
> usb_put_hcd(hcd);
> platform_set_drvdata(dev, NULL);
>
> --
> 1.7.9.5
>

2012-10-05 17:09:11

by Florian Fainelli

[permalink] [raw]
Subject: [PATCH 31/32 v2] USB: EHCI: make ehci-platform use devm_request_and_ioremap helper

This patch changes the ehci-platform driver to use the device managed helper
function for requesting memory region and ioremapping memory resources.
As a result the error path in the probe function is simplified, and the
platform driver remove callback does not longer need to release and iounmap
memory resources. devm_request_and_ioremap() will use either the ioremap()
or ioremap_nocache() handler depending on the resource's CACHEABLE flag, so
we are good with this change.

Signed-off-by: Florian Fainelli <[email protected]>
---
Changes in v2
- use devm_request_and_ioremap instead of two calls

drivers/usb/host/ehci-platform.c | 18 +++---------------
1 file changed, 3 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
index 3cb0b1b..272728c 100644
--- a/drivers/usb/host/ehci-platform.c
+++ b/drivers/usb/host/ehci-platform.c
@@ -123,29 +123,19 @@ static int __devinit ehci_platform_probe(struct platform_device *dev)
hcd->rsrc_start = res_mem->start;
hcd->rsrc_len = resource_size(res_mem);

- if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
- dev_err(&dev->dev, "controller already in use");
- err = -EBUSY;
- goto err_put_hcd;
- }
-
- hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
+ hcd->regs = devm_request_and_ioremap(&dev->dev, res_mem);
if (!hcd->regs) {
err = -ENOMEM;
- goto err_release_region;
+ goto err_put_hcd;
}
err = usb_add_hcd(hcd, irq, IRQF_SHARED);
if (err)
- goto err_iounmap;
+ goto err_put_hcd;

platform_set_drvdata(dev, hcd);

return err;

-err_iounmap:
- iounmap(hcd->regs);
-err_release_region:
- release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
err_put_hcd:
usb_put_hcd(hcd);
err_power:
@@ -161,8 +151,6 @@ static int __devexit ehci_platform_remove(struct platform_device *dev)
struct usb_ehci_pdata *pdata = dev->dev.platform_data;

usb_remove_hcd(hcd);
- iounmap(hcd->regs);
- release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
usb_put_hcd(hcd);
platform_set_drvdata(dev, NULL);

--
1.7.9.5