[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <579F5C69.8070006@laposte.net>
Date: Mon, 1 Aug 2016 16:27:53 +0200
From: Sebastian Frias <sf84@...oste.net>
To: Thomas Gleixner <tglx@...utronix.de>,
Marc Zyngier <marc.zyngier@....com>,
Jason Cooper <jason@...edaemon.net>
Cc: LKML <linux-kernel@...r.kernel.org>, Mason <slash.tmp@...e.fr>
Subject: [PATCH 2/2] genirq: Generic chip: factorise code using
irq_get_domain_generic_chip()
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@...oste.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
Powered by blists - more mailing lists