diff options
author | Benoit Cousson <b-cousson@ti.com> | 2012-02-01 10:01:39 -0500 |
---|---|---|
committer | Benoit Cousson <b-cousson@ti.com> | 2012-03-05 17:02:52 -0500 |
commit | 96751fcbe5438e95514b025e9cee7a6d38038f40 (patch) | |
tree | b9193d0fcccbac8738cf934e37da1934ab3ebfff | |
parent | 862ff64011e606582cec80cc3fa4fcd3e585d76f (diff) |
gpio/omap: Use devm_ API and add request_mem_region
Replace the regular kzalloc and ioremap with the devm_ equivalent
to simplify error handling.
Add the missing devm_request_mem_region to reserve the region used
by the driver.
Signed-off-by: Benoit Cousson <b-cousson@ti.com>
Cc: Tarun Kanti DebBarma <tarun.kanti@ti.com>
-rw-r--r-- | drivers/gpio/gpio-omap.c | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c index a0c3e03a1d1e..c3a9dc8fe732 100644 --- a/drivers/gpio/gpio-omap.c +++ b/drivers/gpio/gpio-omap.c | |||
@@ -19,7 +19,7 @@ | |||
19 | #include <linux/err.h> | 19 | #include <linux/err.h> |
20 | #include <linux/clk.h> | 20 | #include <linux/clk.h> |
21 | #include <linux/io.h> | 21 | #include <linux/io.h> |
22 | #include <linux/slab.h> | 22 | #include <linux/device.h> |
23 | #include <linux/pm_runtime.h> | 23 | #include <linux/pm_runtime.h> |
24 | #include <linux/pm.h> | 24 | #include <linux/pm.h> |
25 | 25 | ||
@@ -1052,23 +1052,19 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev) | |||
1052 | struct gpio_bank *bank; | 1052 | struct gpio_bank *bank; |
1053 | int ret = 0; | 1053 | int ret = 0; |
1054 | 1054 | ||
1055 | if (!dev->platform_data) { | 1055 | if (!dev->platform_data) |
1056 | ret = -EINVAL; | 1056 | return -EINVAL; |
1057 | goto err_exit; | ||
1058 | } | ||
1059 | 1057 | ||
1060 | bank = kzalloc(sizeof(struct gpio_bank), GFP_KERNEL); | 1058 | bank = devm_kzalloc(&pdev->dev, sizeof(struct gpio_bank), GFP_KERNEL); |
1061 | if (!bank) { | 1059 | if (!bank) { |
1062 | dev_err(dev, "Memory alloc failed\n"); | 1060 | dev_err(dev, "Memory alloc failed\n"); |
1063 | ret = -ENOMEM; | 1061 | return -ENOMEM; |
1064 | goto err_exit; | ||
1065 | } | 1062 | } |
1066 | 1063 | ||
1067 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | 1064 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
1068 | if (unlikely(!res)) { | 1065 | if (unlikely(!res)) { |
1069 | dev_err(dev, "Invalid IRQ resource\n"); | 1066 | dev_err(dev, "Invalid IRQ resource\n"); |
1070 | ret = -ENODEV; | 1067 | return -ENODEV; |
1071 | goto err_free; | ||
1072 | } | 1068 | } |
1073 | 1069 | ||
1074 | bank->irq = res->start; | 1070 | bank->irq = res->start; |
@@ -1096,15 +1092,19 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev) | |||
1096 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 1092 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
1097 | if (unlikely(!res)) { | 1093 | if (unlikely(!res)) { |
1098 | dev_err(dev, "Invalid mem resource\n"); | 1094 | dev_err(dev, "Invalid mem resource\n"); |
1099 | ret = -ENODEV; | 1095 | return -ENODEV; |
1100 | goto err_free; | 1096 | } |
1097 | |||
1098 | if (!devm_request_mem_region(dev, res->start, resource_size(res), | ||
1099 | pdev->name)) { | ||
1100 | dev_err(dev, "Region already claimed\n"); | ||
1101 | return -EBUSY; | ||
1101 | } | 1102 | } |
1102 | 1103 | ||
1103 | bank->base = ioremap(res->start, resource_size(res)); | 1104 | bank->base = devm_ioremap(dev, res->start, resource_size(res)); |
1104 | if (!bank->base) { | 1105 | if (!bank->base) { |
1105 | dev_err(dev, "Could not ioremap\n"); | 1106 | dev_err(dev, "Could not ioremap\n"); |
1106 | ret = -ENOMEM; | 1107 | return -ENOMEM; |
1107 | goto err_free; | ||
1108 | } | 1108 | } |
1109 | 1109 | ||
1110 | platform_set_drvdata(pdev, bank); | 1110 | platform_set_drvdata(pdev, bank); |
@@ -1125,11 +1125,6 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev) | |||
1125 | list_add_tail(&bank->node, &omap_gpio_list); | 1125 | list_add_tail(&bank->node, &omap_gpio_list); |
1126 | 1126 | ||
1127 | return ret; | 1127 | return ret; |
1128 | |||
1129 | err_free: | ||
1130 | kfree(bank); | ||
1131 | err_exit: | ||
1132 | return ret; | ||
1133 | } | 1128 | } |
1134 | 1129 | ||
1135 | #ifdef CONFIG_ARCH_OMAP2PLUS | 1130 | #ifdef CONFIG_ARCH_OMAP2PLUS |