diff options
| author | Guenter Roeck <linux@roeck-us.net> | 2012-06-02 15:22:08 -0400 |
|---|---|---|
| committer | Guenter Roeck <linux@roeck-us.net> | 2012-09-24 00:08:33 -0400 |
| commit | b25df2bfbe2e7faddbb4f517e39de0323eef3ec7 (patch) | |
| tree | b76f1fe83dcd25c4ce9bc6475e86bcd51b8f4b7c /drivers/hwmon | |
| parent | 816864d9968814c23c12e6601ad7dd1dabb8f994 (diff) | |
hwmon: (jz4740-hwmon) Convert to use devm_ functions
Convert to use devm_ functions to reduce code size and simplify the code.
Cc: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
| -rw-r--r-- | drivers/hwmon/jz4740-hwmon.c | 53 |
1 files changed, 16 insertions, 37 deletions
diff --git a/drivers/hwmon/jz4740-hwmon.c b/drivers/hwmon/jz4740-hwmon.c index 5253d23361d9..dee9eec2036e 100644 --- a/drivers/hwmon/jz4740-hwmon.c +++ b/drivers/hwmon/jz4740-hwmon.c | |||
| @@ -20,6 +20,7 @@ | |||
| 20 | #include <linux/mutex.h> | 20 | #include <linux/mutex.h> |
| 21 | #include <linux/platform_device.h> | 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
| 23 | #include <linux/io.h> | ||
| 23 | 24 | ||
| 24 | #include <linux/completion.h> | 25 | #include <linux/completion.h> |
| 25 | #include <linux/mfd/core.h> | 26 | #include <linux/mfd/core.h> |
| @@ -106,42 +107,37 @@ static int __devinit jz4740_hwmon_probe(struct platform_device *pdev) | |||
| 106 | int ret; | 107 | int ret; |
| 107 | struct jz4740_hwmon *hwmon; | 108 | struct jz4740_hwmon *hwmon; |
| 108 | 109 | ||
| 109 | hwmon = kmalloc(sizeof(*hwmon), GFP_KERNEL); | 110 | hwmon = devm_kzalloc(&pdev->dev, sizeof(*hwmon), GFP_KERNEL); |
| 110 | if (!hwmon) { | 111 | if (!hwmon) |
| 111 | dev_err(&pdev->dev, "Failed to allocate driver structure\n"); | ||
| 112 | return -ENOMEM; | 112 | return -ENOMEM; |
| 113 | } | ||
| 114 | 113 | ||
| 115 | hwmon->cell = mfd_get_cell(pdev); | 114 | hwmon->cell = mfd_get_cell(pdev); |
| 116 | 115 | ||
| 117 | hwmon->irq = platform_get_irq(pdev, 0); | 116 | hwmon->irq = platform_get_irq(pdev, 0); |
| 118 | if (hwmon->irq < 0) { | 117 | if (hwmon->irq < 0) { |
| 119 | ret = hwmon->irq; | 118 | dev_err(&pdev->dev, "Failed to get platform irq: %d\n", |
| 120 | dev_err(&pdev->dev, "Failed to get platform irq: %d\n", ret); | 119 | hwmon->irq); |
| 121 | goto err_free; | 120 | return hwmon->irq; |
| 122 | } | 121 | } |
| 123 | 122 | ||
| 124 | hwmon->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 123 | hwmon->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 125 | if (!hwmon->mem) { | 124 | if (!hwmon->mem) { |
| 126 | ret = -ENOENT; | ||
| 127 | dev_err(&pdev->dev, "Failed to get platform mmio resource\n"); | 125 | dev_err(&pdev->dev, "Failed to get platform mmio resource\n"); |
| 128 | goto err_free; | 126 | return -ENOENT; |
| 129 | } | 127 | } |
| 130 | 128 | ||
| 131 | hwmon->mem = request_mem_region(hwmon->mem->start, | 129 | hwmon->mem = devm_request_mem_region(&pdev->dev, hwmon->mem->start, |
| 132 | resource_size(hwmon->mem), pdev->name); | 130 | resource_size(hwmon->mem), pdev->name); |
| 133 | if (!hwmon->mem) { | 131 | if (!hwmon->mem) { |
| 134 | ret = -EBUSY; | ||
| 135 | dev_err(&pdev->dev, "Failed to request mmio memory region\n"); | 132 | dev_err(&pdev->dev, "Failed to request mmio memory region\n"); |
| 136 | goto err_free; | 133 | return -EBUSY; |
| 137 | } | 134 | } |
| 138 | 135 | ||
| 139 | hwmon->base = ioremap_nocache(hwmon->mem->start, | 136 | hwmon->base = devm_ioremap_nocache(&pdev->dev, hwmon->mem->start, |
| 140 | resource_size(hwmon->mem)); | 137 | resource_size(hwmon->mem)); |
| 141 | if (!hwmon->base) { | 138 | if (!hwmon->base) { |
| 142 | ret = -EBUSY; | ||
| 143 | dev_err(&pdev->dev, "Failed to ioremap mmio memory\n"); | 139 | dev_err(&pdev->dev, "Failed to ioremap mmio memory\n"); |
| 144 | goto err_release_mem_region; | 140 | return -EBUSY; |
| 145 | } | 141 | } |
| 146 | 142 | ||
| 147 | init_completion(&hwmon->read_completion); | 143 | init_completion(&hwmon->read_completion); |
| @@ -149,17 +145,18 @@ static int __devinit jz4740_hwmon_probe(struct platform_device *pdev) | |||
| 149 | 145 | ||
| 150 | platform_set_drvdata(pdev, hwmon); | 146 | platform_set_drvdata(pdev, hwmon); |
| 151 | 147 | ||
| 152 | ret = request_irq(hwmon->irq, jz4740_hwmon_irq, 0, pdev->name, hwmon); | 148 | ret = devm_request_irq(&pdev->dev, hwmon->irq, jz4740_hwmon_irq, 0, |
| 149 | pdev->name, hwmon); | ||
| 153 | if (ret) { | 150 | if (ret) { |
| 154 | dev_err(&pdev->dev, "Failed to request irq: %d\n", ret); | 151 | dev_err(&pdev->dev, "Failed to request irq: %d\n", ret); |
| 155 | goto err_iounmap; | 152 | return ret; |
| 156 | } | 153 | } |
| 157 | disable_irq(hwmon->irq); | 154 | disable_irq(hwmon->irq); |
| 158 | 155 | ||
| 159 | ret = sysfs_create_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group); | 156 | ret = sysfs_create_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group); |
| 160 | if (ret) { | 157 | if (ret) { |
| 161 | dev_err(&pdev->dev, "Failed to create sysfs group: %d\n", ret); | 158 | dev_err(&pdev->dev, "Failed to create sysfs group: %d\n", ret); |
| 162 | goto err_free_irq; | 159 | return ret; |
| 163 | } | 160 | } |
| 164 | 161 | ||
| 165 | hwmon->hwmon = hwmon_device_register(&pdev->dev); | 162 | hwmon->hwmon = hwmon_device_register(&pdev->dev); |
| @@ -172,16 +169,6 @@ static int __devinit jz4740_hwmon_probe(struct platform_device *pdev) | |||
| 172 | 169 | ||
| 173 | err_remove_file: | 170 | err_remove_file: |
| 174 | sysfs_remove_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group); | 171 | sysfs_remove_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group); |
| 175 | err_free_irq: | ||
| 176 | free_irq(hwmon->irq, hwmon); | ||
| 177 | err_iounmap: | ||
| 178 | platform_set_drvdata(pdev, NULL); | ||
| 179 | iounmap(hwmon->base); | ||
| 180 | err_release_mem_region: | ||
| 181 | release_mem_region(hwmon->mem->start, resource_size(hwmon->mem)); | ||
| 182 | err_free: | ||
| 183 | kfree(hwmon); | ||
| 184 | |||
| 185 | return ret; | 172 | return ret; |
| 186 | } | 173 | } |
| 187 | 174 | ||
| @@ -192,14 +179,6 @@ static int __devexit jz4740_hwmon_remove(struct platform_device *pdev) | |||
| 192 | hwmon_device_unregister(hwmon->hwmon); | 179 | hwmon_device_unregister(hwmon->hwmon); |
| 193 | sysfs_remove_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group); | 180 | sysfs_remove_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group); |
| 194 | 181 | ||
| 195 | free_irq(hwmon->irq, hwmon); | ||
| 196 | |||
| 197 | iounmap(hwmon->base); | ||
| 198 | release_mem_region(hwmon->mem->start, resource_size(hwmon->mem)); | ||
| 199 | |||
| 200 | platform_set_drvdata(pdev, NULL); | ||
| 201 | kfree(hwmon); | ||
| 202 | |||
| 203 | return 0; | 182 | return 0; |
| 204 | } | 183 | } |
| 205 | 184 | ||
