genirq/generic_chip: Get rid of code duplication
authorSebastian Frias <sf84@laposte.net>
Mon, 1 Aug 2016 14:27:53 +0000 (16:27 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Fri, 2 Sep 2016 16:06:49 +0000 (18:06 +0200)
irq_map_generic_chip() contains about the same code as
irq_get_domain_generic_chip() except for the return values.

Split out the irq_get_domain_generic_chip() implementation so it can be
reused.

[ tglx: Removed the extra churn in irq_get_domain_generic_chip() callers
   and massaged changelog ]

Signed-off-by: Sebastian Frias <sf84@laposte.net>
Cc: Marc Zyngier <marc.zyngier@arm.com>
Cc: Mason <slash.tmp@free.fr>
Cc: Jason Cooper <jason@lakedaemon.net>
Link: http://lkml.kernel.org/r/579F5C69.8070006@laposte.net
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
kernel/irq/generic-chip.c

index 5fbb94b077b375bb7f414e09b5e1ca1dd0f7b032..11ad73b39d2eaaf718f05ce2c1a4504f1010c5b7 100644 (file)
@@ -328,6 +328,20 @@ int irq_alloc_domain_generic_chips(struct irq_domain *d, int irqs_per_chip,
 }
 EXPORT_SYMBOL_GPL(irq_alloc_domain_generic_chips);
 
+static struct irq_chip_generic *
+__irq_get_domain_generic_chip(struct irq_domain *d, unsigned int hw_irq)
+{
+       struct irq_domain_chip_generic *dgc = d->gc;
+       int idx;
+
+       if (!dgc)
+               return ERR_PTR(-ENODEV);
+       idx = hw_irq / dgc->irqs_per_chip;
+       if (idx >= dgc->num_chips)
+               return ERR_PTR(-EINVAL);
+       return dgc->gc[idx];
+}
+
 /**
  * irq_get_domain_generic_chip - Get a pointer to the generic chip of a hw_irq
  * @d:                 irq domain pointer
@@ -336,15 +350,9 @@ EXPORT_SYMBOL_GPL(irq_alloc_domain_generic_chips);
 struct irq_chip_generic *
 irq_get_domain_generic_chip(struct irq_domain *d, unsigned int hw_irq)
 {
-       struct irq_domain_chip_generic *dgc = d->gc;
-       int idx;
+       struct irq_chip_generic *gc = __irq_get_domain_generic_chip(d, hw_irq);
 
-       if (!dgc)
-               return NULL;
-       idx = hw_irq / dgc->irqs_per_chip;
-       if (idx >= dgc->num_chips)
-               return NULL;
-       return dgc->gc[idx];
+       return !IS_ERR(gc) ? gc : NULL;
 }
 EXPORT_SYMBOL_GPL(irq_get_domain_generic_chip);
 
@@ -368,13 +376,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;
 
This page took 0.025489 seconds and 5 git commands to generate.