From: Sebastian Frias <sf84@laposte.net>
To: Thomas Gleixner <tglx@linutronix.de>,
Marc Zyngier <marc.zyngier@arm.com>,
Jason Cooper <jason@lakedaemon.net>
Cc: LKML <linux-kernel@vger.kernel.org>, Mason <slash.tmp@free.fr>
Subject: [PATCH 2/2] genirq: Generic chip: factorise code using irq_get_domain_generic_chip()
Date: Mon, 1 Aug 2016 16:27:53 +0200 [thread overview]
Message-ID: <579F5C69.8070006@laposte.net> (raw)
irq_map_generic_chip() contains about the same code as
irq_get_domain_generic_chip() except for the return values. Using ERR_PTR()
along with IS_ERR() and PTR_ERR() it is possible to make the map (and
unmap) functions call irq_get_domain_generic_chip instead of duplicating
the code.
irq_get_domain_generic_chip() is modified to return different error codes
using ERR_PTR() to preserve error information.
Most callers of irq_get_domain_generic_chip() do not check for its return
value and assume it is always a valid pointer. The two drivers that do
check for its return value are updated to use IS_ERR()
Fixes: 088f40b7b027 ("genirq: Generic chip: Add linear irq domain support")
Signed-off-by: Sebastian Frias <sf84@laposte.net>
---
drivers/gpio/gpio-dwapb.c | 2 +-
drivers/irqchip/irq-atmel-aic-common.c | 2 +-
kernel/irq/generic-chip.c | 24 ++++++++----------------
3 files changed, 10 insertions(+), 18 deletions(-)
diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c
index 34779bb..157d684 100644
--- a/drivers/gpio/gpio-dwapb.c
+++ b/drivers/gpio/gpio-dwapb.c
@@ -317,7 +317,7 @@ static void dwapb_configure_irqs(struct dwapb_gpio *gpio,
}
irq_gc = irq_get_domain_generic_chip(gpio->domain, 0);
- if (!irq_gc) {
+ if (IS_ERR(irq_gc)) {
irq_domain_remove(gpio->domain);
gpio->domain = NULL;
return;
diff --git a/drivers/irqchip/irq-atmel-aic-common.c b/drivers/irqchip/irq-atmel-aic-common.c
index 28b26c8..33205211 100644
--- a/drivers/irqchip/irq-atmel-aic-common.c
+++ b/drivers/irqchip/irq-atmel-aic-common.c
@@ -122,7 +122,7 @@ static void __init aic_common_ext_irq_of_init(struct irq_domain *domain)
of_property_for_each_u32(node, "atmel,external-irqs", prop, p, hwirq) {
gc = irq_get_domain_generic_chip(domain, hwirq);
- if (!gc) {
+ if (IS_ERR(gc)) {
pr_warn("AIC: external irq %d >= %d skip it\n",
hwirq, domain->revmap_size);
continue;
diff --git a/kernel/irq/generic-chip.c b/kernel/irq/generic-chip.c
index f7d6654..3ccac06 100644
--- a/kernel/irq/generic-chip.c
+++ b/kernel/irq/generic-chip.c
@@ -350,10 +350,10 @@ irq_get_domain_generic_chip(struct irq_domain *d, unsigned int hw_irq)
int idx;
if (!dgc)
- return NULL;
+ return ERR_PTR(-ENODEV);
idx = hw_irq / dgc->irqs_per_chip;
if (idx >= dgc->num_chips)
- return NULL;
+ return ERR_PTR(-EINVAL);
return dgc->gc[idx];
}
EXPORT_SYMBOL_GPL(irq_get_domain_generic_chip);
@@ -378,13 +378,9 @@ int irq_map_generic_chip(struct irq_domain *d, unsigned int virq,
unsigned long flags;
int idx;
- if (!d->gc)
- return -ENODEV;
-
- idx = hw_irq / dgc->irqs_per_chip;
- if (idx >= dgc->num_chips)
- return -EINVAL;
- gc = dgc->gc[idx];
+ gc = irq_get_domain_generic_chip(d, hw_irq);
+ if (IS_ERR(gc))
+ return PTR_ERR(gc);
idx = hw_irq % dgc->irqs_per_chip;
@@ -433,15 +429,11 @@ void irq_unmap_generic_chip(struct irq_domain *d, unsigned int virq)
struct irq_domain_chip_generic *dgc = d->gc;
struct irq_chip_generic *gc;
unsigned int hw_irq = data->hwirq;
- int chip_idx, irq_idx;
-
- if (!d->gc)
- return;
+ int irq_idx;
- chip_idx = hw_irq / dgc->irqs_per_chip;
- if (chip_idx >= dgc->num_chips)
+ gc = irq_get_domain_generic_chip(d, hw_irq);
+ if (IS_ERR(gc))
return;
- gc = dgc->gc[chip_idx];
irq_idx = hw_irq % dgc->irqs_per_chip;
--
1.7.11.2
next reply other threads:[~2016-08-01 14:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-01 14:27 Sebastian Frias [this message]
2016-09-02 15:42 ` [PATCH 2/2] genirq: Generic chip: factorise code using irq_get_domain_generic_chip() Thomas Gleixner
2016-09-02 16:14 ` [tip:irq/core] genirq/generic_chip: Get rid of code duplication tip-bot for Sebastian Frias
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=579F5C69.8070006@laposte.net \
--to=sf84@laposte.net \
--cc=jason@lakedaemon.net \
--cc=linux-kernel@vger.kernel.org \
--cc=marc.zyngier@arm.com \
--cc=slash.tmp@free.fr \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.