提交 8944df72 编写于 作者: T Tobias Klauser 提交者: Linus Walleij

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: NTobias Klauser <tklauser@distanz.ch>
Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
上级 ddffeb8c
...@@ -216,39 +216,34 @@ static void __init pl061_init_gc(struct pl061_gpio *chip, int irq_base) ...@@ -216,39 +216,34 @@ static void __init pl061_init_gc(struct pl061_gpio *chip, int irq_base)
IRQ_GC_INIT_NESTED_LOCK, IRQ_NOREQUEST, 0); IRQ_GC_INIT_NESTED_LOCK, IRQ_NOREQUEST, 0);
} }
static int pl061_probe(struct amba_device *dev, const struct amba_id *id) static int pl061_probe(struct amba_device *adev, const struct amba_id *id)
{ {
struct pl061_platform_data *pdata; struct device *dev = &adev->dev;
struct pl061_platform_data *pdata = dev->platform_data;
struct pl061_gpio *chip; struct pl061_gpio *chip;
int ret, irq, i; int ret, irq, i;
chip = kzalloc(sizeof(*chip), GFP_KERNEL); chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
if (chip == NULL) if (chip == NULL)
return -ENOMEM; return -ENOMEM;
pdata = dev->dev.platform_data;
if (pdata) { if (pdata) {
chip->gc.base = pdata->gpio_base; chip->gc.base = pdata->gpio_base;
chip->irq_base = pdata->irq_base; chip->irq_base = pdata->irq_base;
} else if (dev->dev.of_node) { } else if (adev->dev.of_node) {
chip->gc.base = -1; chip->gc.base = -1;
chip->irq_base = 0; chip->irq_base = 0;
} else { } else
ret = -ENODEV; return -ENODEV;
goto free_mem;
}
if (!request_mem_region(dev->res.start, if (!devm_request_mem_region(dev, adev->res.start,
resource_size(&dev->res), "pl061")) { resource_size(&adev->res), "pl061"))
ret = -EBUSY; return -EBUSY;
goto free_mem;
}
chip->base = ioremap(dev->res.start, resource_size(&dev->res)); chip->base = devm_ioremap(dev, adev->res.start,
if (chip->base == NULL) { resource_size(&adev->res));
ret = -ENOMEM; if (chip->base == NULL)
goto release_region; return -ENOMEM;
}
spin_lock_init(&chip->lock); spin_lock_init(&chip->lock);
...@@ -258,13 +253,13 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id) ...@@ -258,13 +253,13 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
chip->gc.set = pl061_set_value; chip->gc.set = pl061_set_value;
chip->gc.to_irq = pl061_to_irq; chip->gc.to_irq = pl061_to_irq;
chip->gc.ngpio = PL061_GPIO_NR; chip->gc.ngpio = PL061_GPIO_NR;
chip->gc.label = dev_name(&dev->dev); chip->gc.label = dev_name(dev);
chip->gc.dev = &dev->dev; chip->gc.dev = dev;
chip->gc.owner = THIS_MODULE; chip->gc.owner = THIS_MODULE;
ret = gpiochip_add(&chip->gc); ret = gpiochip_add(&chip->gc);
if (ret) if (ret)
goto iounmap; return ret;
/* /*
* irq_chip support * irq_chip support
...@@ -276,11 +271,10 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id) ...@@ -276,11 +271,10 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
pl061_init_gc(chip, chip->irq_base); pl061_init_gc(chip, chip->irq_base);
writeb(0, chip->base + GPIOIE); /* disable irqs */ writeb(0, chip->base + GPIOIE); /* disable irqs */
irq = dev->irq[0]; irq = adev->irq[0];
if (irq < 0) { if (irq < 0)
ret = -ENODEV; return -ENODEV;
goto iounmap;
}
irq_set_chained_handler(irq, pl061_irq_handler); irq_set_chained_handler(irq, pl061_irq_handler);
irq_set_handler_data(irq, chip); irq_set_handler_data(irq, chip);
...@@ -294,18 +288,9 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id) ...@@ -294,18 +288,9 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
} }
} }
amba_set_drvdata(dev, chip); amba_set_drvdata(adev, chip);
return 0; return 0;
iounmap:
iounmap(chip->base);
release_region:
release_mem_region(dev->res.start, resource_size(&dev->res));
free_mem:
kfree(chip);
return ret;
} }
#ifdef CONFIG_PM #ifdef CONFIG_PM
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册