Skip to contentSkip to conversation

gpio/langwell: re-read the IRQ status register after each iteration

PATCH Applied Mika Westerberg 4 participants 5 messages May 10, 2012 – May 11, 2012 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio/langwell: re-read the IRQ status register after each iteration

Spotted by Grant Likely. The IRQ status register should be re-read after each iteration. Otherwise the loop misses the interrupt if it gets raised immediately after handled.

---
This patch applies on top of my previous patch ("gpio: langwell: convert to use irq_domain").

 drivers/gpio/gpio-langwell.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
drivers/gpio/gpio-langwell.c +1 -3
index b067357..a1c8754 100644
@@ -250,11 +250,9 @@ static void lnw_irq_handler(unsigned irq, struct irq_desc *desc)
 	/* check GPIO controller to check which pin triggered the interrupt */
 	for (base = 0; base < lnw->chip.ngpio; base += 32) {
 		gedr = gpio_reg(&lnw->chip, base, GEDR);
-		pending = readl(gedr);
-		while (pending) {
+		while ((pending = readl(gedr))) {
 			gpio = __ffs(pending);
 			mask = BIT(gpio);
-			pending &= ~mask;
 			/* Clear before handling so we can't lose an edge */
 			writel(mask, gedr);
 			generic_handle_irq(irq_find_mapping(lnw->domain,
Signature · 1 line
1.7.9.1
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Mika Westerberg

Spotted by Grant Likely. The IRQ status register should be re-read after each iteration. Otherwise the loop misses the interrupt if it gets raised immediately after handled.

---
This patch applies on top of my previous patch ("gpio: langwell: convert to use irq_domain").

Oh yeah that thing I recognize!

If someone has time I think it would be a good idea to conjure a cocienelle sematic patch to catch this pattern, because I suspect it might exist in more IRQ handlers.

-               pending = readl(gedr);
-               while (pending) {
+               while ((pending = readl(gedr))) {
                       gpio = __ffs(pending);
                       mask = BIT(gpio);

- pending &= ~mask;

Yours,
Linus Walleij

#2 lore raw
Quoted 19 lines · Linus Walleij
Quoted 8 lines · Mika Westerberg

Spotted by Grant Likely. The IRQ status register should be re-read after each iteration. Otherwise the loop misses the interrupt if it gets raised immediately after handled.

---
This patch applies on top of my previous patch ("gpio: langwell: convert to use irq_domain").

Oh yeah that thing I recognize!

If someone has time I think it would be a good idea to conjure a cocienelle sematic patch to catch this pattern, because I suspect it might exist in more IRQ handlers.

drivers/gpio/gpio-langwell.c static void lnw_irq_handler(unsigned irq, struct irq_desc *desc) · line 257

Quoted 6 lines
drivers/gpio/gpio-langwell.c +1 -3
-               pending = readl(gedr);
-               while (pending) {
+               while ((pending = readl(gedr))) {
                      gpio = __ffs(pending);
                      mask = BIT(gpio);
-                       pending &= ~mask;

I tried the following:

@@
expression pending,gedr,e1;
statement S;
@@

*pending = readl(gedr);
... when != pending = e1
while (pending) S

That is, a readl call followed by a while loop with no reassignment of pending.

Perhaps the following are suspicious:

arch/arm/mach-msm/dma.c, function msm_datamover_irq_handler drivers/gpio/gpio-msm-v1.c, function msm_gpio_irq_handler

But I am not completely sure to understand what is wanted (or not wanted).

julia

#3 lore raw
Quoted 14 lines · Julia Lawall

I tried the following:

@@
expression pending,gedr,e1;
statement S;
@@

*pending = readl(gedr);
... when != pending = e1
while (pending) S

That is, a readl call followed by a while loop with no reassignment of pending.

Quoted 6 lines

Perhaps the following are suspicious:

arch/arm/mach-msm/dma.c, function msm_datamover_irq_handler drivers/gpio/gpio-msm-v1.c, function msm_gpio_irq_handler

But I am not completely sure to understand what is wanted (or not wanted).

No problem, I will look at them.
Thanks Julia!

Yours,
Linus Walleij

Applied
#4 lore raw
In reply to Linus Walleij
Quoted 7 lines · Linus Walleij
Quoted 4 lines · Mika Westerberg

Spotted by Grant Likely. The IRQ status register should be re-read after each iteration. Otherwise the loop misses the interrupt if it gets raised immediately after handled.

Quoted 7 lines
Quoted 4 lines

---
This patch applies on top of my previous patch ("gpio: langwell: convert to use irq_domain").

Oh yeah that thing I recognize!

Applied, thanks.

g.