usb: host: uhci-grlib.c : use devm_ functions
Subsystems (2)
PATCH 1/1 usb: host: uhci-grlib.c : use devm_ functions
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.
--- drivers/usb/host/uhci-grlib.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-)
drivers/usb/host/uhci-grlib.c +7 -19
@@ -17,6 +17,7 @@* (C) Copyright 2004-2007 Alan Stern, [email protected] */ +#include <linux/device.h> #include <linux/of_irq.h> #include <linux/of_address.h> #include <linux/of_platform.h>
@@ -113,23 +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_rmr; } - hcd->regs =ioremap (hcd->rsrc_start, hcd->rsrc_len); -if (!hcd->regs) { -printk (KERN_ERR "%s: ioremap failed\n" , __FILE__); - rv = -ENOMEM ; + hcd->regs =devm_ioremap_resource (&op->dev, hcd->rsrc_start, + hcd->rsrc_len); +if (IS_ERR (hcd->regs)) { + rv =PTR_ERR (hcd->regs); goto err_ioremap; }
@@ -139,17 +134,13 @@ static int uhci_hcd_grlib_probe(struct platform_device *op) rv =usb_add_hcd (hcd, irq,0 );if (rv) - goto err_uhci; + goto err_ioremap;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:usb_put_hcd (hcd);
@@ -164,10 +155,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 ;
Signature · 1 line
1.9.1
Quoted 10 lines · Himangi Saraogi
The various
devm_functions allocate memory that is released when a driver detaches. This patch usesdevm_ioremap_resourcefor 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.his added to make sure the devm_*() routine declarations are unambiguously available.Signed-off-by Himangi Saraogi <[email protected]>Acked-by Julia Lawall <[email protected]>
Included Jan Andersson (the original author) in the loop.
Sam
Quoted 85 lines
--- drivers/usb/host/uhci-grlib.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-)drivers/usb/host/uhci-grlib.c +7
-19@@ -17,6 +17,7 @@* (C) Copyright 2004-2007 Alan Stern, [email protected] */ +#include <linux/device.h> #include <linux/of_irq.h> #include <linux/of_address.h> #include <linux/of_platform.h> @@ -113,23 +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_rmr; } - hcd->regs =ioremap (hcd->rsrc_start, hcd->rsrc_len); -if (!hcd->regs) { -printk (KERN_ERR "%s: ioremap failed\n" , __FILE__); - rv = -ENOMEM ; + hcd->regs =devm_ioremap_resource (&op->dev, hcd->rsrc_start, + hcd->rsrc_len); +if (IS_ERR (hcd->regs)) { + rv =PTR_ERR (hcd->regs); goto err_ioremap; }@@ -139,17 +134,13 @@ static int uhci_hcd_grlib_probe(struct platform_device *op) rv =usb_add_hcd (hcd, irq,0 );if (rv) - goto err_uhci; + goto err_ioremap;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:usb_put_hcd (hcd);@@ -164,10 +155,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 ;Signature · 7 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Quoted 32 lines · Himangi Saraogi
The various
devm_functions allocate memory that is released when a driver detaches. This patch usesdevm_ioremap_resourcefor 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.his added to make sure the devm_*() routine declarations are unambiguously available.Signed-off-by Himangi Saraogi <[email protected]>Acked-by Julia Lawall <[email protected]>--- drivers/usb/host/uhci-grlib.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-)drivers/usb/host/uhci-grlib.c +1
-2@@ -17,6 +17,7 @@* (C) Copyright 2004-2007 Alan Stern, [email protected] */ +#include <linux/device.h> #include <linux/of_irq.h> #include <linux/of_address.h> #include <linux/of_platform.h> @@ -113,23 +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__);
drivers/usb/host/uhci-grlib.c static int uhci_hcd_grlib_probe(struct platform_device *op) · line 121
Quoted 10 lines
drivers/usb/host/uhci-grlib.c +1
-5- 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_rmr;
Getting rid of request_mem_region, you should rather rename the err_rmr to err_irq, to keep the original label naming pattern. Or maybe better yet, change naming pattern, as now two failure points are jumping to the same label for the second one.
drivers/usb/host/uhci-grlib.c static int uhci_hcd_grlib_probe(struct platform_device *op) · line 129
Quoted 12 lines
drivers/usb/host/uhci-grlib.c +4
-4} - hcd->regs =ioremap (hcd->rsrc_start, hcd->rsrc_len); -if (!hcd->regs) { -printk (KERN_ERR "%s: ioremap failed\n" , __FILE__); - rv = -ENOMEM ; + hcd->regs =devm_ioremap_resource (&op->dev, hcd->rsrc_start, + hcd->rsrc_len); +if (IS_ERR (hcd->regs)) { + rv =PTR_ERR (hcd->regs); goto err_ioremap; }
This does not compile. The call to devm_ioremap_resource should rather be:
hcd->regs = devm_ioremap_resource(&op->dev, &res);
drivers/usb/host/uhci-grlib.c static int uhci_hcd_grlib_probe(struct platform_device *op) · line 137
Quoted 7 lines
drivers/usb/host/uhci-grlib.c +1
-1@@ -139,17 +134,13 @@ static int uhci_hcd_grlib_probe(struct platform_device *op) rv =usb_add_hcd (hcd, irq,0 );if (rv) - goto err_uhci; + goto err_ioremap;
Here the label name also does not make sense anymore.
Best regards,
Andreas Larsson
Software Engineer
Aeroflex Gaisler AB
Aeroflex Microelectronic Solutions – HiRel
Quoted 25 lines
drivers/usb/host/uhci-grlib.c +0
-7device_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:usb_put_hcd (hcd);@@ -164,10 +155,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 ;