mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 2/2] genirq: Generic chip: factorise code using irq_get_domain_generic_chip()
@ 2016-08-01 14:27 Sebastian Frias
  2016-09-02 15:42 ` Thomas Gleixner
  2016-09-02 16:14 ` [tip:irq/core] genirq/generic_chip: Get rid of code duplication tip-bot for Sebastian Frias
  0 siblings, 2 replies; 3+ messages in thread
From: Sebastian Frias @ 2016-08-01 14:27 UTC (permalink / raw)
  To: Thomas Gleixner, Marc Zyngier, Jason Cooper; +Cc: LKML, Mason

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-09-02 16:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-01 14:27 [PATCH 2/2] genirq: Generic chip: factorise code using irq_get_domain_generic_chip() Sebastian Frias
2016-09-02 15:42 ` Thomas Gleixner
2016-09-02 16:14 ` [tip:irq/core] genirq/generic_chip: Get rid of code duplication tip-bot for Sebastian Frias

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome