Commit 4770533f authored by Geert Uytterhoeven's avatar Geert Uytterhoeven Committed by Marc Zyngier

irqchip/renesas-irqc: Convert to managed initializations

Simplify error handling by converting the driver to use managed
allocations and initializations.

Note that platform_get_resource() and ioremap_nocache() are combined in
devm_platform_ioremap_resource().
Signed-off-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: default avatarSimon Horman <horms+renesas@verge.net.au>
Signed-off-by: default avatarMarc Zyngier <marc.zyngier@arm.com>
parent 000e20c5
...@@ -126,16 +126,13 @@ static int irqc_probe(struct platform_device *pdev) ...@@ -126,16 +126,13 @@ static int irqc_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
const char *name = dev_name(dev); const char *name = dev_name(dev);
struct irqc_priv *p; struct irqc_priv *p;
struct resource *io;
struct resource *irq; struct resource *irq;
int ret; int ret;
int k; int k;
p = kzalloc(sizeof(*p), GFP_KERNEL); p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL);
if (!p) { if (!p)
ret = -ENOMEM; return -ENOMEM;
goto err0;
}
p->dev = dev; p->dev = dev;
platform_set_drvdata(pdev, p); platform_set_drvdata(pdev, p);
...@@ -143,14 +140,6 @@ static int irqc_probe(struct platform_device *pdev) ...@@ -143,14 +140,6 @@ static int irqc_probe(struct platform_device *pdev)
pm_runtime_enable(dev); pm_runtime_enable(dev);
pm_runtime_get_sync(dev); pm_runtime_get_sync(dev);
/* get hold of manadatory IOMEM */
io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!io) {
dev_err(dev, "not enough IOMEM resources\n");
ret = -EINVAL;
goto err1;
}
/* allow any number of IRQs between 1 and IRQC_IRQ_MAX */ /* allow any number of IRQs between 1 and IRQC_IRQ_MAX */
for (k = 0; k < IRQC_IRQ_MAX; k++) { for (k = 0; k < IRQC_IRQ_MAX; k++) {
irq = platform_get_resource(pdev, IORESOURCE_IRQ, k); irq = platform_get_resource(pdev, IORESOURCE_IRQ, k);
...@@ -166,14 +155,14 @@ static int irqc_probe(struct platform_device *pdev) ...@@ -166,14 +155,14 @@ static int irqc_probe(struct platform_device *pdev)
if (p->number_of_irqs < 1) { if (p->number_of_irqs < 1) {
dev_err(dev, "not enough IRQ resources\n"); dev_err(dev, "not enough IRQ resources\n");
ret = -EINVAL; ret = -EINVAL;
goto err1; goto err_runtime_pm_disable;
} }
/* ioremap IOMEM and setup read/write callbacks */ /* ioremap IOMEM and setup read/write callbacks */
p->iomem = ioremap_nocache(io->start, resource_size(io)); p->iomem = devm_platform_ioremap_resource(pdev, 0);
if (!p->iomem) { if (IS_ERR(p->iomem)) {
ret = -ENXIO; ret = PTR_ERR(p->iomem);
goto err2; goto err_runtime_pm_disable;
} }
p->cpu_int_base = p->iomem + IRQC_INT_CPU_BASE(0); /* SYS-SPI */ p->cpu_int_base = p->iomem + IRQC_INT_CPU_BASE(0); /* SYS-SPI */
...@@ -183,7 +172,7 @@ static int irqc_probe(struct platform_device *pdev) ...@@ -183,7 +172,7 @@ static int irqc_probe(struct platform_device *pdev)
if (!p->irq_domain) { if (!p->irq_domain) {
ret = -ENXIO; ret = -ENXIO;
dev_err(dev, "cannot initialize irq domain\n"); dev_err(dev, "cannot initialize irq domain\n");
goto err2; goto err_runtime_pm_disable;
} }
ret = irq_alloc_domain_generic_chips(p->irq_domain, p->number_of_irqs, ret = irq_alloc_domain_generic_chips(p->irq_domain, p->number_of_irqs,
...@@ -191,7 +180,7 @@ static int irqc_probe(struct platform_device *pdev) ...@@ -191,7 +180,7 @@ static int irqc_probe(struct platform_device *pdev)
0, 0, IRQ_GC_INIT_NESTED_LOCK); 0, 0, IRQ_GC_INIT_NESTED_LOCK);
if (ret) { if (ret) {
dev_err(dev, "cannot allocate generic chip\n"); dev_err(dev, "cannot allocate generic chip\n");
goto err3; goto err_remove_domain;
} }
p->gc = irq_get_domain_generic_chip(p->irq_domain, 0); p->gc = irq_get_domain_generic_chip(p->irq_domain, 0);
...@@ -206,46 +195,33 @@ static int irqc_probe(struct platform_device *pdev) ...@@ -206,46 +195,33 @@ static int irqc_probe(struct platform_device *pdev)
/* request interrupts one by one */ /* request interrupts one by one */
for (k = 0; k < p->number_of_irqs; k++) { for (k = 0; k < p->number_of_irqs; k++) {
if (request_irq(p->irq[k].requested_irq, irqc_irq_handler, if (devm_request_irq(dev, p->irq[k].requested_irq,
0, name, &p->irq[k])) { irqc_irq_handler, 0, name, &p->irq[k])) {
dev_err(dev, "failed to request IRQ\n"); dev_err(dev, "failed to request IRQ\n");
ret = -ENOENT; ret = -ENOENT;
goto err4; goto err_remove_domain;
} }
} }
dev_info(dev, "driving %d irqs\n", p->number_of_irqs); dev_info(dev, "driving %d irqs\n", p->number_of_irqs);
return 0; return 0;
err4:
while (--k >= 0)
free_irq(p->irq[k].requested_irq, &p->irq[k]);
err3: err_remove_domain:
irq_domain_remove(p->irq_domain); irq_domain_remove(p->irq_domain);
err2: err_runtime_pm_disable:
iounmap(p->iomem);
err1:
pm_runtime_put(dev); pm_runtime_put(dev);
pm_runtime_disable(dev); pm_runtime_disable(dev);
kfree(p);
err0:
return ret; return ret;
} }
static int irqc_remove(struct platform_device *pdev) static int irqc_remove(struct platform_device *pdev)
{ {
struct irqc_priv *p = platform_get_drvdata(pdev); struct irqc_priv *p = platform_get_drvdata(pdev);
int k;
for (k = 0; k < p->number_of_irqs; k++)
free_irq(p->irq[k].requested_irq, &p->irq[k]);
irq_domain_remove(p->irq_domain); irq_domain_remove(p->irq_domain);
iounmap(p->iomem);
pm_runtime_put(&pdev->dev); pm_runtime_put(&pdev->dev);
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
kfree(p);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment