Skip to contentSkip to conversation

uhci-platform: use devm_ioremap resource

PATCH In review Himangi Saraogi 3 participants 5 messages Jun 11, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 uhci-platform: use devm_ioremap resource

This patch replaces the memory allocation using request_mem_region and the ioremap by a single call to managed interface devm_ioremap_reource. The corresponding calls to release_mem_region and iounmap in the probe and release functions are now unnecessary and are removed. Also a label is done away with and linux/device.h is added to make sure the devm_*() outine declarations are unambiguously available.

---
v2: pass correct arguments to devm_ioremap_resource Not compile tested due to incompatible architecture.

 drivers/usb/host/uhci-platform.c | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)
drivers/usb/host/uhci-platform.c +5 -17
index 01833ab..b987f1d 100644
@@ -8,6 +8,7 @@
  */
 
 #include <linux/of.h>
+#include <linux/device.h>
 #include <linux/platform_device.h>
 
 static int uhci_platform_init(struct usb_hcd *hcd)
@@ -88,33 +89,22 @@ static int uhci_hcd_platform_probe(struct platform_device *pdev)
 	hcd->rsrc_start = res->start;
 	hcd->rsrc_len = resource_size(res);
 
-	if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
-		pr_err("%s: request_mem_region failed\n", __func__);
-		ret = -EBUSY;
+	hcd->regs = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(hcd->regs)) {
+		ret = PTR_ERR(hcd->regs);
 		goto err_rmr;
 	}
-
-	hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
-	if (!hcd->regs) {
-		pr_err("%s: ioremap failed\n", __func__);
-		ret = -ENOMEM;
-		goto err_irq;
-	}
 	uhci = hcd_to_uhci(hcd);
 
 	uhci->regs = hcd->regs;
 
 	ret = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED);
 	if (ret)
-		goto err_uhci;
+		goto err_rmr;
 
 	device_wakeup_enable(hcd->self.controller);
 	return 0;
 
-err_uhci:
-	iounmap(hcd->regs);
-err_irq:
-	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
 err_rmr:
 	usb_put_hcd(hcd);
 
@@ -126,8 +116,6 @@ static int uhci_hcd_platform_remove(struct platform_device *pdev)
 	struct usb_hcd *hcd = platform_get_drvdata(pdev);
 
 	usb_remove_hcd(hcd);
-	iounmap(hcd->regs);
-	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
 	usb_put_hcd(hcd);
 
 	return 0;
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 7 lines · Himangi Saraogi

This patch replaces the memory allocation using request_mem_region and the ioremap by a single call to managed interface devm_ioremap_reource. The corresponding calls to release_mem_region and iounmap in the probe and release functions are now unnecessary and are removed. Also a label is done away with and linux/device.h is added to make sure the devm_*() outine declarations are unambiguously available.

Quoted 5 lines

---
v2: pass correct arguments to devm_ioremap_resource Not compile tested due to incompatible architecture.

uhci-platform is compatible with all architectures. But you have to add it to the .config file by hand.

Quoted 16 lines
 drivers/usb/host/uhci-platform.c | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)
drivers/usb/host/uhci-platform.c +1 -0
index 01833ab..b987f1d 100644
@@ -8,6 +8,7 @@
  */
 
 #include <linux/of.h>
+#include <linux/device.h>
 #include <linux/platform_device.h>
 
 static int uhci_platform_init(struct usb_hcd *hcd)

drivers/usb/host/uhci-platform.c static int uhci_hcd_platform_probe(struct platform_device *pdev) · line 95

Quoted 10 lines
drivers/usb/host/uhci-platform.c +3 -3
@@ -88,33 +89,22 @@ static int uhci_hcd_platform_probe(struct platform_device *pdev)
 	hcd->rsrc_start = res->start;
 	hcd->rsrc_len = resource_size(res);
 
-	if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
-		pr_err("%s: request_mem_region failed\n", __func__);
-		ret = -EBUSY;
+	hcd->regs = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(hcd->regs)) {
+		ret = PTR_ERR(hcd->regs);
 		goto err_rmr;

Again, you didn't adjust the statement label. The "rmr" in err_rmr stands for "request_mem_region", so it is clearly out of place in your patch.

Alan Stern

#2 lore raw
Quoted 5 lines
Quoted 2 lines

v2: pass correct arguments to devm_ioremap_resource Not compile tested due to incompatible architecture.

uhci-platform is compatible with all architectures. But you have to add it to the .config file by hand.

What should one do exactly? I added

CONFIG_USB_UHCI_PLATFORM=y

to the end of my .config file, but then running make just overwrites it:

Quoted 1 line

make drivers/usb/host/uhci-platform.o

scripts/kconfig/conf --silentoldconfig Kconfig
#

# configuration written to .config
#
  CHK     include/config/kernel.release
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  CALL    scripts/checksyscalls.sh
  CC      drivers/usb/host/uhci-platform.o
drivers/usb/host/uhci-platform.c:13:38: warning: ?struct usb_hcd? declared
inside parameter list [enabled by default]
 static int uhci_platform_init(struct usb_hcd *hcd)
                                      ^

thanks,
julia

maintainer
#3 lore raw
Quoted 11 lines · Julia Lawall
Quoted 5 lines
Quoted 2 lines

v2: pass correct arguments to devm_ioremap_resource Not compile tested due to incompatible architecture.

uhci-platform is compatible with all architectures. But you have to add it to the .config file by hand.

What should one do exactly? I added

CONFIG_USB_UHCI_PLATFORM=y

to the end of my .config file, but then running make just overwrites it:

By golly, you're right... I didn't realize it would do that.

I guess you have to edit the drivers/usb/host/Kconfig file, changing

config USB_UHCI_PLATFORM
bool
default y if ARCH_VT8500

to

config USB_UHCI_PLATFORM
bool
default y

or something equivalent.

Quoted 4 lines
Quoted 2 lines

make drivers/usb/host/uhci-platform.o

scripts/kconfig/conf --silentoldconfig Kconfig
#

Quoted 10 lines
# configuration written to .config
#
  CHK     include/config/kernel.release
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  CALL    scripts/checksyscalls.sh
  CC      drivers/usb/host/uhci-platform.o
drivers/usb/host/uhci-platform.c:13:38: warning: ?struct usb_hcd? declared
inside parameter list [enabled by default]
 static int uhci_platform_init(struct usb_hcd *hcd)

Do

make drivers/usb/host/uhci-hcd.o

instead of

make drivers/usb/host/uhci-platform.o

Alan Stern

#4 lore raw
Quoted 45 lines · Alan Stern
Quoted 11 lines · Julia Lawall
Quoted 5 lines
Quoted 2 lines

v2: pass correct arguments to devm_ioremap_resource Not compile tested due to incompatible architecture.

uhci-platform is compatible with all architectures. But you have to add it to the .config file by hand.

What should one do exactly? I added

CONFIG_USB_UHCI_PLATFORM=y

to the end of my .config file, but then running make just overwrites it:

By golly, you're right... I didn't realize it would do that.

I guess you have to edit the drivers/usb/host/Kconfig file, changing

config USB_UHCI_PLATFORM
bool
default y if ARCH_VT8500

to

config USB_UHCI_PLATFORM
bool
default y

or something equivalent.

Quoted 4 lines
Quoted 2 lines

make drivers/usb/host/uhci-platform.o

scripts/kconfig/conf --silentoldconfig Kconfig
#

Quoted 10 lines
# configuration written to .config
#
  CHK     include/config/kernel.release
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  CALL    scripts/checksyscalls.sh
  CC      drivers/usb/host/uhci-platform.o
drivers/usb/host/uhci-platform.c:13:38: warning: ?struct usb_hcd? declared
inside parameter list [enabled by default]
 static int uhci_platform_init(struct usb_hcd *hcd)
Quoted 7 lines

Do

make drivers/usb/host/uhci-hcd.o

instead of

make drivers/usb/host/uhci-platform.o

OK, thanks for the explanations.

julia