public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] usb: host: uhci-grlib.c : use devm_ functions
@ 2014-06-11 18:38 Himangi Saraogi
  2014-06-11 18:54 ` Alan Stern
  2014-06-12  5:49 ` Andreas Larsson
  0 siblings, 2 replies; 3+ messages in thread
From: Himangi Saraogi @ 2014-06-11 18:38 UTC (permalink / raw)
  To: Alan Stern, Greg Kroah-Hartman, linux-usb, linux-kernel,
	Jan Andersson
  Cc: Andreas Larsson, julia.lawall

The various devm_ functions allocate memory that is released when a
driver detaches. This patch uses devm_ioremap_resource for data
that is allocated in the probe function of a platform device and
is only freed in the remove function. The corresponding free functions
are removed and two labels are done away with. Also, linux/device.h
is added to make sure the devm_*() routine declarations are
unambiguously available.

Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
---
Not compile tested due to incompatible architecture.
v3: pass correct arguments to devm_ioremap_resource

 drivers/usb/host/uhci-grlib.c | 31 +++++++++----------------------
 1 file changed, 9 insertions(+), 22 deletions(-)

diff --git a/drivers/usb/host/uhci-grlib.c b/drivers/usb/host/uhci-grlib.c
index ab25dc3..05f57ff 100644
--- a/drivers/usb/host/uhci-grlib.c
+++ b/drivers/usb/host/uhci-grlib.c
@@ -17,6 +17,7 @@
  * (C) Copyright 2004-2007 Alan Stern, stern@rowland.harvard.edu
  */
 
+#include <linux/device.h>
 #include <linux/of_irq.h>
 #include <linux/of_address.h>
 #include <linux/of_platform.h>
@@ -113,24 +114,17 @@ static int uhci_hcd_grlib_probe(struct platform_device *op)
 	hcd->rsrc_start = res.start;
 	hcd->rsrc_len = resource_size(&res);
 
-	if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
-		printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__);
-		rv = -EBUSY;
-		goto err_rmr;
-	}
-
 	irq = irq_of_parse_and_map(dn, 0);
 	if (irq == NO_IRQ) {
 		printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
 		rv = -EBUSY;
-		goto err_irq;
+		goto err_usb;
 	}
 
-	hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
-	if (!hcd->regs) {
-		printk(KERN_ERR "%s: ioremap failed\n", __FILE__);
-		rv = -ENOMEM;
-		goto err_ioremap;
+	hcd->regs = devm_ioremap_resource(&op->dev, &res);
+	if (IS_ERR(hcd->regs)) {
+		rv = PTR_ERR(hcd->regs);
+		goto err_irq;
 	}
 
 	uhci = hcd_to_uhci(hcd);
@@ -139,18 +133,14 @@ static int uhci_hcd_grlib_probe(struct platform_device *op)
 
 	rv = usb_add_hcd(hcd, irq, 0);
 	if (rv)
-		goto err_uhci;
+		goto err_irq;
 
 	device_wakeup_enable(hcd->self.controller);
 	return 0;
 
-err_uhci:
-	iounmap(hcd->regs);
-err_ioremap:
-	irq_dispose_mapping(irq);
 err_irq:
-	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
-err_rmr:
+	irq_dispose_mapping(irq);
+err_usb:
 	usb_put_hcd(hcd);
 
 	return rv;
@@ -164,10 +154,7 @@ static int uhci_hcd_grlib_remove(struct platform_device *op)
 
 	usb_remove_hcd(hcd);
 
-	iounmap(hcd->regs);
 	irq_dispose_mapping(hcd->irq);
-	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
-
 	usb_put_hcd(hcd);
 
 	return 0;
-- 
1.9.1


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

* Re: [PATCH v3] usb: host: uhci-grlib.c : use devm_ functions
  2014-06-11 18:38 [PATCH v3] usb: host: uhci-grlib.c : use devm_ functions Himangi Saraogi
@ 2014-06-11 18:54 ` Alan Stern
  2014-06-12  5:49 ` Andreas Larsson
  1 sibling, 0 replies; 3+ messages in thread
From: Alan Stern @ 2014-06-11 18:54 UTC (permalink / raw)
  To: Himangi Saraogi
  Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, Jan Andersson,
	Andreas Larsson, julia.lawall

On Thu, 12 Jun 2014, Himangi Saraogi wrote:

> The various devm_ functions allocate memory that is released when a
> driver detaches. This patch uses devm_ioremap_resource for data
> that is allocated in the probe function of a platform device and
> is only freed in the remove function. The corresponding free functions
> are removed and two labels are done away with. Also, linux/device.h
> is added to make sure the devm_*() routine declarations are
> unambiguously available.
> 
> Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
> ---
> Not compile tested due to incompatible architecture.
> v3: pass correct arguments to devm_ioremap_resource

Acked-by: Alan Stern <stern@rowland.harvard.edu>

What happened to the corresponding patch for uhci-platform.c?

Alan Stern


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

* Re: [PATCH v3] usb: host: uhci-grlib.c : use devm_ functions
  2014-06-11 18:38 [PATCH v3] usb: host: uhci-grlib.c : use devm_ functions Himangi Saraogi
  2014-06-11 18:54 ` Alan Stern
@ 2014-06-12  5:49 ` Andreas Larsson
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Larsson @ 2014-06-12  5:49 UTC (permalink / raw)
  To: Himangi Saraogi, Alan Stern, Greg Kroah-Hartman, linux-usb,
	linux-kernel, Jan Andersson
  Cc: julia.lawall

On 2014-06-11 20:38, Himangi Saraogi wrote:
> The various devm_ functions allocate memory that is released when a
> driver detaches. This patch uses devm_ioremap_resource for data
> that is allocated in the probe function of a platform device and
> is only freed in the remove function. The corresponding free functions
> are removed and two labels are done away with. Also, linux/device.h
> is added to make sure the devm_*() routine declarations are
> unambiguously available.
>
> Signed-off-by: Himangi Saraogi <himangi774@gmail.com>

Looks and works fine now!

Acked-by: Andreas Larsson <andreas@gaisler.com>

Best regards,
Andreas Larsson

> ---
> Not compile tested due to incompatible architecture.
> v3: pass correct arguments to devm_ioremap_resource
>
>   drivers/usb/host/uhci-grlib.c | 31 +++++++++----------------------
>   1 file changed, 9 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/usb/host/uhci-grlib.c b/drivers/usb/host/uhci-grlib.c
> index ab25dc3..05f57ff 100644
> --- a/drivers/usb/host/uhci-grlib.c
> +++ b/drivers/usb/host/uhci-grlib.c
> @@ -17,6 +17,7 @@
>    * (C) Copyright 2004-2007 Alan Stern, stern@rowland.harvard.edu
>    */
>
> +#include <linux/device.h>
>   #include <linux/of_irq.h>
>   #include <linux/of_address.h>
>   #include <linux/of_platform.h>
> @@ -113,24 +114,17 @@ static int uhci_hcd_grlib_probe(struct platform_device *op)
>   	hcd->rsrc_start = res.start;
>   	hcd->rsrc_len = resource_size(&res);
>
> -	if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
> -		printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__);
> -		rv = -EBUSY;
> -		goto err_rmr;
> -	}
> -
>   	irq = irq_of_parse_and_map(dn, 0);
>   	if (irq == NO_IRQ) {
>   		printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
>   		rv = -EBUSY;
> -		goto err_irq;
> +		goto err_usb;
>   	}
>
> -	hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
> -	if (!hcd->regs) {
> -		printk(KERN_ERR "%s: ioremap failed\n", __FILE__);
> -		rv = -ENOMEM;
> -		goto err_ioremap;
> +	hcd->regs = devm_ioremap_resource(&op->dev, &res);
> +	if (IS_ERR(hcd->regs)) {
> +		rv = PTR_ERR(hcd->regs);
> +		goto err_irq;
>   	}
>
>   	uhci = hcd_to_uhci(hcd);
> @@ -139,18 +133,14 @@ static int uhci_hcd_grlib_probe(struct platform_device *op)
>
>   	rv = usb_add_hcd(hcd, irq, 0);
>   	if (rv)
> -		goto err_uhci;
> +		goto err_irq;
>
>   	device_wakeup_enable(hcd->self.controller);
>   	return 0;
>
> -err_uhci:
> -	iounmap(hcd->regs);
> -err_ioremap:
> -	irq_dispose_mapping(irq);
>   err_irq:
> -	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
> -err_rmr:
> +	irq_dispose_mapping(irq);
> +err_usb:
>   	usb_put_hcd(hcd);
>
>   	return rv;
> @@ -164,10 +154,7 @@ static int uhci_hcd_grlib_remove(struct platform_device *op)
>
>   	usb_remove_hcd(hcd);
>
> -	iounmap(hcd->regs);
>   	irq_dispose_mapping(hcd->irq);
> -	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
> -
>   	usb_put_hcd(hcd);
>
>   	return 0;
>

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

end of thread, other threads:[~2014-06-12  5:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-11 18:38 [PATCH v3] usb: host: uhci-grlib.c : use devm_ functions Himangi Saraogi
2014-06-11 18:54 ` Alan Stern
2014-06-12  5:49 ` Andreas Larsson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox