From: Geert Uytterhoeven <geert+renesas@glider.be>
To: Thomas Gleixner <tglx@linutronix.de>,
Jason Cooper <jason@lakedaemon.net>,
Marc Zyngier <marc.zyngier@arm.com>
Cc: linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org,
Geert Uytterhoeven <geert+renesas@glider.be>
Subject: [PATCH 5/5] irqchip/renesas-irqc: Convert to managed initializations
Date: Mon, 29 Apr 2019 17:20:06 +0200 [thread overview]
Message-ID: <20190429152006.22593-6-geert+renesas@glider.be> (raw)
In-Reply-To: <20190429152006.22593-1-geert+renesas@glider.be>
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: Geert Uytterhoeven <geert+renesas@glider.be>
---
drivers/irqchip/irq-renesas-irqc.c | 54 +++++++++---------------------
1 file changed, 15 insertions(+), 39 deletions(-)
diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
index af03ee31a87bb11d..cde9f9c0687e94a4 100644
--- a/drivers/irqchip/irq-renesas-irqc.c
+++ b/drivers/irqchip/irq-renesas-irqc.c
@@ -126,16 +126,13 @@ static int irqc_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
const char *name = dev_name(dev);
struct irqc_priv *p;
- struct resource *io;
struct resource *irq;
int ret;
int k;
- p = kzalloc(sizeof(*p), GFP_KERNEL);
- if (!p) {
- ret = -ENOMEM;
- goto err0;
- }
+ p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL);
+ if (!p)
+ return -ENOMEM;
p->dev = dev;
platform_set_drvdata(pdev, p);
@@ -143,14 +140,6 @@ static int irqc_probe(struct platform_device *pdev)
pm_runtime_enable(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 */
for (k = 0; k < IRQC_IRQ_MAX; k++) {
irq = platform_get_resource(pdev, IORESOURCE_IRQ, k);
@@ -166,14 +155,14 @@ static int irqc_probe(struct platform_device *pdev)
if (p->number_of_irqs < 1) {
dev_err(dev, "not enough IRQ resources\n");
ret = -EINVAL;
- goto err1;
+ goto err_runtime_pm_disable;
}
/* ioremap IOMEM and setup read/write callbacks */
- p->iomem = ioremap_nocache(io->start, resource_size(io));
- if (!p->iomem) {
- ret = -ENXIO;
- goto err2;
+ p->iomem = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(p->iomem)) {
+ ret = PTR_ERR(p->iomem);
+ goto err_runtime_pm_disable;
}
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)
if (!p->irq_domain) {
ret = -ENXIO;
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,
@@ -191,7 +180,7 @@ static int irqc_probe(struct platform_device *pdev)
0, 0, IRQ_GC_INIT_NESTED_LOCK);
if (ret) {
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);
@@ -206,46 +195,33 @@ static int irqc_probe(struct platform_device *pdev)
/* request interrupts one by one */
for (k = 0; k < p->number_of_irqs; k++) {
- if (request_irq(p->irq[k].requested_irq, irqc_irq_handler,
- 0, name, &p->irq[k])) {
+ if (devm_request_irq(dev, p->irq[k].requested_irq,
+ irqc_irq_handler, 0, name, &p->irq[k])) {
dev_err(dev, "failed to request IRQ\n");
ret = -ENOENT;
- goto err4;
+ goto err_remove_domain;
}
}
dev_info(dev, "driving %d irqs\n", p->number_of_irqs);
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);
-err2:
- iounmap(p->iomem);
-err1:
+err_runtime_pm_disable:
pm_runtime_put(dev);
pm_runtime_disable(dev);
- kfree(p);
-err0:
return ret;
}
static int irqc_remove(struct platform_device *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);
- iounmap(p->iomem);
pm_runtime_put(&pdev->dev);
pm_runtime_disable(&pdev->dev);
- kfree(p);
return 0;
}
--
2.17.1
next prev parent reply other threads:[~2019-04-29 15:20 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-29 15:20 [PATCH 0/5] irqchip/renesas-irqc: Miscellaneous cleanups and improvements Geert Uytterhoeven
2019-04-29 15:20 ` [PATCH 1/5] irqchip/renesas-irqc: Remove unneeded inclusion of <linux/spinlock.h> Geert Uytterhoeven
2019-05-13 12:04 ` Simon Horman
2019-04-29 15:20 ` [PATCH 2/5] irqchip/renesas-irqc: Remove devm_kzalloc()/ioremap_nocache() error printing Geert Uytterhoeven
2019-04-30 8:12 ` Sergei Shtylyov
2019-04-30 11:59 ` Geert Uytterhoeven
2019-05-13 12:04 ` Simon Horman
2019-04-29 15:20 ` [PATCH 3/5] irqchip/renesas-irqc: Add helper variable dev = &pdev->dev Geert Uytterhoeven
2019-05-13 12:15 ` Simon Horman
2019-04-29 15:20 ` [PATCH 4/5] irqchip/renesas-irqc: Replace irqc_priv.pdev by irqc_priv.dev Geert Uytterhoeven
2019-05-13 12:15 ` Simon Horman
2019-04-29 15:20 ` Geert Uytterhoeven [this message]
2019-05-13 12:15 ` [PATCH 5/5] irqchip/renesas-irqc: Convert to managed initializations Simon Horman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190429152006.22593-6-geert+renesas@glider.be \
--to=geert+renesas@glider.be \
--cc=jason@lakedaemon.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=marc.zyngier@arm.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).