aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2012-10-05 05:45:28 -0400
committerLinus Walleij <linus.walleij@linaro.org>2012-10-15 14:50:13 -0400
commit8944df726c7d2916764d18be8e944bd7ea3f2f51 (patch)
tree62a9373b9e614771f17af6bcd6432ab657fb5846
parentddffeb8c4d0331609ef2581d84de4d763607bd37 (diff)
gpio/gpio-pl061: Covert to use devm_* functions
Use the devm_* family of functions during probe to reduce the error handling code footprint. Signed-off-by: Tobias Klauser <tklauser@distanz.ch> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r--drivers/gpio/gpio-pl061.c59
1 files changed, 22 insertions, 37 deletions
diff --git a/drivers/gpio/gpio-pl061.c b/drivers/gpio/gpio-pl061.c
index b4b5da4fd2cc..31d9c9e79ea9 100644
--- a/drivers/gpio/gpio-pl061.c
+++ b/drivers/gpio/gpio-pl061.c
@@ -216,39 +216,34 @@ static void __init pl061_init_gc(struct pl061_gpio *chip, int irq_base)
216 IRQ_GC_INIT_NESTED_LOCK, IRQ_NOREQUEST, 0); 216 IRQ_GC_INIT_NESTED_LOCK, IRQ_NOREQUEST, 0);
217} 217}
218 218
219static int pl061_probe(struct amba_device *dev, const struct amba_id *id) 219static int pl061_probe(struct amba_device *adev, const struct amba_id *id)
220{ 220{
221 struct pl061_platform_data *pdata; 221 struct device *dev = &adev->dev;
222 struct pl061_platform_data *pdata = dev->platform_data;
222 struct pl061_gpio *chip; 223 struct pl061_gpio *chip;
223 int ret, irq, i; 224 int ret, irq, i;
224 225
225 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 226 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
226 if (chip == NULL) 227 if (chip == NULL)
227 return -ENOMEM; 228 return -ENOMEM;
228 229
229 pdata = dev->dev.platform_data;
230 if (pdata) { 230 if (pdata) {
231 chip->gc.base = pdata->gpio_base; 231 chip->gc.base = pdata->gpio_base;
232 chip->irq_base = pdata->irq_base; 232 chip->irq_base = pdata->irq_base;
233 } else if (dev->dev.of_node) { 233 } else if (adev->dev.of_node) {
234 chip->gc.base = -1; 234 chip->gc.base = -1;
235 chip->irq_base = 0; 235 chip->irq_base = 0;
236 } else { 236 } else
237 ret = -ENODEV; 237 return -ENODEV;
238 goto free_mem;
239 }
240 238
241 if (!request_mem_region(dev->res.start, 239 if (!devm_request_mem_region(dev, adev->res.start,
242 resource_size(&dev->res), "pl061")) { 240 resource_size(&adev->res), "pl061"))
243 ret = -EBUSY; 241 return -EBUSY;
244 goto free_mem;
245 }
246 242
247 chip->base = ioremap(dev->res.start, resource_size(&dev->res)); 243 chip->base = devm_ioremap(dev, adev->res.start,
248 if (chip->base == NULL) { 244 resource_size(&adev->res));
249 ret = -ENOMEM; 245 if (chip->base == NULL)
250 goto release_region; 246 return -ENOMEM;
251 }
252 247
253 spin_lock_init(&chip->lock); 248 spin_lock_init(&chip->lock);
254 249
@@ -258,13 +253,13 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
258 chip->gc.set = pl061_set_value; 253 chip->gc.set = pl061_set_value;
259 chip->gc.to_irq = pl061_to_irq; 254 chip->gc.to_irq = pl061_to_irq;
260 chip->gc.ngpio = PL061_GPIO_NR; 255 chip->gc.ngpio = PL061_GPIO_NR;
261 chip->gc.label = dev_name(&dev->dev); 256 chip->gc.label = dev_name(dev);
262 chip->gc.dev = &dev->dev; 257 chip->gc.dev = dev;
263 chip->gc.owner = THIS_MODULE; 258 chip->gc.owner = THIS_MODULE;
264 259
265 ret = gpiochip_add(&chip->gc); 260 ret = gpiochip_add(&chip->gc);
266 if (ret) 261 if (ret)
267 goto iounmap; 262 return ret;
268 263
269 /* 264 /*
270 * irq_chip support 265 * irq_chip support
@@ -276,11 +271,10 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
276 pl061_init_gc(chip, chip->irq_base); 271 pl061_init_gc(chip, chip->irq_base);
277 272
278 writeb(0, chip->base + GPIOIE); /* disable irqs */ 273 writeb(0, chip->base + GPIOIE); /* disable irqs */
279 irq = dev->irq[0]; 274 irq = adev->irq[0];
280 if (irq < 0) { 275 if (irq < 0)
281 ret = -ENODEV; 276 return -ENODEV;
282 goto iounmap; 277
283 }
284 irq_set_chained_handler(irq, pl061_irq_handler); 278 irq_set_chained_handler(irq, pl061_irq_handler);
285 irq_set_handler_data(irq, chip); 279 irq_set_handler_data(irq, chip);
286 280
@@ -294,18 +288,9 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
294 } 288 }
295 } 289 }
296 290
297 amba_set_drvdata(dev, chip); 291 amba_set_drvdata(adev, chip);
298 292
299 return 0; 293 return 0;
300
301iounmap:
302 iounmap(chip->base);
303release_region:
304 release_mem_region(dev->res.start, resource_size(&dev->res));
305free_mem:
306 kfree(chip);
307
308 return ret;
309} 294}
310 295
311#ifdef CONFIG_PM 296#ifdef CONFIG_PM