mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-12 08:48:48 +00:00
gpio/mxs: use devm_* helpers to make error handling simple
It uses devm_* helpers to make the error handling of probe clean and simple. Signed-off-by: Shawn Guo <shawn.guo@linaro.org> Acked-by: Linus Walleij <linus.walleij@linaro.org>
This commit is contained in:
parent
84f3570a96
commit
940a4f7b51
@ -186,44 +186,29 @@ static int __devinit mxs_gpio_probe(struct platform_device *pdev)
|
|||||||
struct resource *iores = NULL;
|
struct resource *iores = NULL;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
port = kzalloc(sizeof(struct mxs_gpio_port), GFP_KERNEL);
|
port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL);
|
||||||
if (!port)
|
if (!port)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
port->id = pdev->id;
|
port->id = pdev->id;
|
||||||
port->virtual_irq_start = MXS_GPIO_IRQ_START + port->id * 32;
|
port->virtual_irq_start = MXS_GPIO_IRQ_START + port->id * 32;
|
||||||
|
|
||||||
|
port->irq = platform_get_irq(pdev, 0);
|
||||||
|
if (port->irq < 0)
|
||||||
|
return port->irq;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* map memory region only once, as all the gpio ports
|
* map memory region only once, as all the gpio ports
|
||||||
* share the same one
|
* share the same one
|
||||||
*/
|
*/
|
||||||
if (!base) {
|
if (!base) {
|
||||||
iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||||
if (!iores) {
|
base = devm_request_and_ioremap(&pdev->dev, iores);
|
||||||
err = -ENODEV;
|
if (!base)
|
||||||
goto out_kfree;
|
return -EADDRNOTAVAIL;
|
||||||
}
|
|
||||||
|
|
||||||
if (!request_mem_region(iores->start, resource_size(iores),
|
|
||||||
pdev->name)) {
|
|
||||||
err = -EBUSY;
|
|
||||||
goto out_kfree;
|
|
||||||
}
|
|
||||||
|
|
||||||
base = ioremap(iores->start, resource_size(iores));
|
|
||||||
if (!base) {
|
|
||||||
err = -ENOMEM;
|
|
||||||
goto out_release_mem;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
port->base = base;
|
port->base = base;
|
||||||
|
|
||||||
port->irq = platform_get_irq(pdev, 0);
|
|
||||||
if (port->irq < 0) {
|
|
||||||
err = -EINVAL;
|
|
||||||
goto out_iounmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* select the pin interrupt functionality but initially
|
* select the pin interrupt functionality but initially
|
||||||
* disable the interrupts
|
* disable the interrupts
|
||||||
@ -246,29 +231,18 @@ static int __devinit mxs_gpio_probe(struct platform_device *pdev)
|
|||||||
port->base + PINCTRL_DOUT(port->id), NULL,
|
port->base + PINCTRL_DOUT(port->id), NULL,
|
||||||
port->base + PINCTRL_DOE(port->id), NULL, false);
|
port->base + PINCTRL_DOE(port->id), NULL, false);
|
||||||
if (err)
|
if (err)
|
||||||
goto out_iounmap;
|
return err;
|
||||||
|
|
||||||
port->bgc.gc.to_irq = mxs_gpio_to_irq;
|
port->bgc.gc.to_irq = mxs_gpio_to_irq;
|
||||||
port->bgc.gc.base = port->id * 32;
|
port->bgc.gc.base = port->id * 32;
|
||||||
|
|
||||||
err = gpiochip_add(&port->bgc.gc);
|
err = gpiochip_add(&port->bgc.gc);
|
||||||
if (err)
|
if (err) {
|
||||||
goto out_bgpio_remove;
|
bgpio_remove(&port->bgc);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out_bgpio_remove:
|
|
||||||
bgpio_remove(&port->bgc);
|
|
||||||
out_iounmap:
|
|
||||||
if (iores)
|
|
||||||
iounmap(port->base);
|
|
||||||
out_release_mem:
|
|
||||||
if (iores)
|
|
||||||
release_mem_region(iores->start, resource_size(iores));
|
|
||||||
out_kfree:
|
|
||||||
kfree(port);
|
|
||||||
dev_info(&pdev->dev, "%s failed with errno %d\n", __func__, err);
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct platform_driver mxs_gpio_driver = {
|
static struct platform_driver mxs_gpio_driver = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user