diff options
author | Chris Packham <chris.packham@alliedtelesis.co.nz> | 2017-06-25 20:44:33 -0400 |
---|---|---|
committer | Wolfram Sang <wsa@the-dreams.de> | 2017-06-27 15:50:21 -0400 |
commit | fa70ca7c287ee63b790fbb3de624a0c80a6e2be2 (patch) | |
tree | 29cbe94be74e4cf94e9d24a890bbe4d77e92ae32 | |
parent | 0e8ce93bdceb6d36a3c1db2227d3f51168fb796c (diff) |
i2c: pca-platform: use device managed allocations
Switch to using the devm_ APIs and remove the now unnecessary error
handling and most of the device removal code.
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
[wsa: adapted error handling I added in previous patch]
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
-rw-r--r-- | drivers/i2c/busses/i2c-pca-platform.c | 59 |
1 files changed, 12 insertions, 47 deletions
diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c index 31d7f76ddd94..7db481cbf402 100644 --- a/drivers/i2c/busses/i2c-pca-platform.c +++ b/drivers/i2c/busses/i2c-pca-platform.c | |||
@@ -143,35 +143,23 @@ static int i2c_pca_pf_probe(struct platform_device *pdev) | |||
143 | int ret = 0; | 143 | int ret = 0; |
144 | int irq; | 144 | int irq; |
145 | 145 | ||
146 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
147 | irq = platform_get_irq(pdev, 0); | 146 | irq = platform_get_irq(pdev, 0); |
148 | /* If irq is 0, we do polling. */ | 147 | /* If irq is 0, we do polling. */ |
149 | if (irq < 0) | 148 | if (irq < 0) |
150 | irq = 0; | 149 | irq = 0; |
151 | 150 | ||
152 | if (res == NULL) { | 151 | i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); |
153 | ret = -ENODEV; | 152 | if (!i2c) |
154 | goto e_print; | 153 | return -ENOMEM; |
155 | } | ||
156 | 154 | ||
157 | if (!request_mem_region(res->start, resource_size(res), res->name)) { | 155 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
158 | ret = -ENOMEM; | 156 | i2c->reg_base = devm_ioremap_resource(&pdev->dev, res); |
159 | goto e_print; | 157 | if (IS_ERR(i2c->reg_base)) |
160 | } | 158 | return PTR_ERR(i2c->reg_base); |
161 | 159 | ||
162 | i2c = kzalloc(sizeof(struct i2c_pca_pf_data), GFP_KERNEL); | ||
163 | if (!i2c) { | ||
164 | ret = -ENOMEM; | ||
165 | goto e_alloc; | ||
166 | } | ||
167 | 160 | ||
168 | init_waitqueue_head(&i2c->wait); | 161 | init_waitqueue_head(&i2c->wait); |
169 | 162 | ||
170 | i2c->reg_base = ioremap(res->start, resource_size(res)); | ||
171 | if (!i2c->reg_base) { | ||
172 | ret = -ENOMEM; | ||
173 | goto e_remap; | ||
174 | } | ||
175 | i2c->io_base = res->start; | 163 | i2c->io_base = res->start; |
176 | i2c->io_size = resource_size(res); | 164 | i2c->io_size = resource_size(res); |
177 | i2c->irq = irq; | 165 | i2c->irq = irq; |
@@ -205,10 +193,8 @@ static int i2c_pca_pf_probe(struct platform_device *pdev) | |||
205 | } else if (np) { | 193 | } else if (np) { |
206 | i2c->adap.timeout = HZ; | 194 | i2c->adap.timeout = HZ; |
207 | i2c->gpio = devm_gpiod_get_optional(&pdev->dev, "reset-gpios", GPIOD_OUT_LOW); | 195 | i2c->gpio = devm_gpiod_get_optional(&pdev->dev, "reset-gpios", GPIOD_OUT_LOW); |
208 | if (IS_ERR(i2c->gpio)) { | 196 | if (IS_ERR(i2c->gpio)) |
209 | ret = PTR_ERR(i2c->gpio); | 197 | return PTR_ERR(i2c->gpio); |
210 | goto e_reqirq; | ||
211 | } | ||
212 | of_property_read_u32_index(np, "clock-frequency", 0, | 198 | of_property_read_u32_index(np, "clock-frequency", 0, |
213 | &i2c->algo_data.i2c_clock); | 199 | &i2c->algo_data.i2c_clock); |
214 | } else { | 200 | } else { |
@@ -238,15 +224,14 @@ static int i2c_pca_pf_probe(struct platform_device *pdev) | |||
238 | } | 224 | } |
239 | 225 | ||
240 | if (irq) { | 226 | if (irq) { |
241 | ret = request_irq(irq, i2c_pca_pf_handler, | 227 | ret = devm_request_irq(&pdev->dev, irq, i2c_pca_pf_handler, |
242 | IRQF_TRIGGER_FALLING, pdev->name, i2c); | 228 | IRQF_TRIGGER_FALLING, pdev->name, i2c); |
243 | if (ret) | 229 | if (ret) |
244 | goto e_reqirq; | 230 | return ret; |
245 | } | 231 | } |
246 | 232 | ||
247 | if (i2c_pca_add_numbered_bus(&i2c->adap) < 0) { | 233 | if (i2c_pca_add_numbered_bus(&i2c->adap) < 0) { |
248 | ret = -ENODEV; | 234 | return -ENODEV; |
249 | goto e_adapt; | ||
250 | } | 235 | } |
251 | 236 | ||
252 | platform_set_drvdata(pdev, i2c); | 237 | platform_set_drvdata(pdev, i2c); |
@@ -254,19 +239,6 @@ static int i2c_pca_pf_probe(struct platform_device *pdev) | |||
254 | printk(KERN_INFO "%s registered.\n", i2c->adap.name); | 239 | printk(KERN_INFO "%s registered.\n", i2c->adap.name); |
255 | 240 | ||
256 | return 0; | 241 | return 0; |
257 | |||
258 | e_adapt: | ||
259 | if (irq) | ||
260 | free_irq(irq, i2c); | ||
261 | e_reqirq: | ||
262 | iounmap(i2c->reg_base); | ||
263 | e_remap: | ||
264 | kfree(i2c); | ||
265 | e_alloc: | ||
266 | release_mem_region(res->start, resource_size(res)); | ||
267 | e_print: | ||
268 | printk(KERN_ERR "Registering PCA9564/PCA9665 FAILED! (%d)\n", ret); | ||
269 | return ret; | ||
270 | } | 242 | } |
271 | 243 | ||
272 | static int i2c_pca_pf_remove(struct platform_device *pdev) | 244 | static int i2c_pca_pf_remove(struct platform_device *pdev) |
@@ -275,13 +247,6 @@ static int i2c_pca_pf_remove(struct platform_device *pdev) | |||
275 | 247 | ||
276 | i2c_del_adapter(&i2c->adap); | 248 | i2c_del_adapter(&i2c->adap); |
277 | 249 | ||
278 | if (i2c->irq) | ||
279 | free_irq(i2c->irq, i2c); | ||
280 | |||
281 | iounmap(i2c->reg_base); | ||
282 | release_mem_region(i2c->io_base, i2c->io_size); | ||
283 | kfree(i2c); | ||
284 | |||
285 | return 0; | 250 | return 0; |
286 | } | 251 | } |
287 | 252 | ||