Skip to contentSkip to conversation

genirq: Genric chip: Use DIV_ROUND_UP to count numchips

RFC PATCH New Axel Lin 2 participants 2 messages Jul 5, 2013 IRQ

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

RFC PATCH 1/1 genirq: Genric chip: Use DIV_ROUND_UP to count numchips

The number of interrupts in a domain may be not divisible by the number of interrupts each chip handles.
Integer division may truncate the result, thus use DIV_ROUND_UP to count numchips.

---
Seems all users of irq_alloc_domain_generic_chips() in current code do not have this issue. I just found the issue while reading the code.

In the commit 02c981c0 of "ARM: CSR: Adding CSR SiRFprimaII board support" It set SIRFSOC_INTENAL_IRQ_END to 59.
So I think this might be a possible case for some hardware.

 kernel/irq/generic-chip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/irq/generic-chip.c +1 -1
index 10e663a..452d6f2 100644
@@ -275,7 +275,7 @@ int irq_alloc_domain_generic_chips(struct irq_domain *d, int irqs_per_chip,
 	if (d->gc)
 		return -EBUSY;
 
-	numchips = d->revmap_size / irqs_per_chip;
+	numchips = DIV_ROUND_UP(d->revmap_size, irqs_per_chip);
 	if (!numchips)
 		return -EINVAL;
 
Signature · 1 line
1.8.1.2
#1 lore raw

[tip:irq/urgent] genirq: generic chip: Use DIV_ROUND_UP to calculate numchips

genirq: generic chip: Use DIV_ROUND_UP to calculate numchips
Commit-ID:  002fca5df168922103a2bb52748f9984e6de80b2
Gitweb:     http://git.kernel.org/tip/002fca5df168922103a2bb52748f9984e6de80b2
Author:     Axel Lin <[email protected]>
AuthorDate: Fri, 5 Jul 2013 17:13:12 +0800
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 5 Jul 2013 11:39:25 +0200

genirq: generic chip: Use DIV_ROUND_UP to calculate numchips

The number of interrupts in a domain may be not divisible by the number of interrupts each chip handles. Integer division may truncate the result, thus use DIV_ROUND_UP to count numchips.

Seems all users of irq_alloc_domain_generic_chips() in current code do not have this issue. I just found the issue while reading the code.

---
 kernel/irq/generic-chip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/irq/generic-chip.c +1 -1
index 1c39ecc..2f274f3 100644
@@ -278,7 +278,7 @@ int irq_alloc_domain_generic_chips(struct irq_domain *d, int irqs_per_chip,
 	if (d->revmap_type != IRQ_DOMAIN_MAP_LINEAR)
 		return -EINVAL;
 
-	numchips = d->revmap_data.linear.size / irqs_per_chip;
+	numchips = DIV_ROUND_UP(d->revmap_data.linear.size, irqs_per_chip);
 	if (!numchips)
 		return -EINVAL;