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

* Re: [PATCH 2/2] genirq: Generic chip: factorise code using irq_get_domain_generic_chip()
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Gleixner @ 2016-09-02 15:42 UTC (permalink / raw)
  To: Sebastian Frias; +Cc: Marc Zyngier, Jason Cooper, LKML, Mason

On Mon, 1 Aug 2016, Sebastian Frias wrote:
> @@ -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);

This is completely pointless churn. None of the existing callsites cares
about the error value. We can simply split out the guts into a static
function and keep the semantics for irq_get_domain_generic_chip.

I'll fix that up while applying it.

Thanks,

	tglx

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

* [tip:irq/core] genirq/generic_chip: Get rid of code duplication
  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-bot for Sebastian Frias
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Sebastian Frias @ 2016-09-02 16:14 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, marc.zyngier, tglx, slash.tmp, jason, linux-kernel, sf84, hpa

Commit-ID:  f0c450eaa364cb77c778f2a46ee2aa3ff464b332
Gitweb:     http://git.kernel.org/tip/f0c450eaa364cb77c778f2a46ee2aa3ff464b332
Author:     Sebastian Frias <sf84@laposte.net>
AuthorDate: Mon, 1 Aug 2016 16:27:53 +0200
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Fri, 2 Sep 2016 18:06:49 +0200

genirq/generic_chip: Get rid of code duplication

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 | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/kernel/irq/generic-chip.c b/kernel/irq/generic-chip.c
index 5fbb94b..11ad73b 100644
--- a/kernel/irq/generic-chip.c
+++ b/kernel/irq/generic-chip.c
@@ -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;
 

^ 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