Skip to contentSkip to conversation

serial: sh-sci: Do not free irqs that have already been freed

PATCH In review Chris Brandt 3 participants 3 messages Jan 28, 2019 – Feb 1, 2019 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 serial: sh-sci: Do not free irqs that have already been freed

Since IRQs might be muxed on some parts, we need to pay attention when we are freeing them.
Otherwise we get the ugly WARNING "Trying to free already-free IRQ 20".

Fixes 628c534ae735 ("serial: sh-sci: Improve support for separate TEI and DRI interrupts")

---
v2:
* fix bad commit grammer

---
 drivers/tty/serial/sh-sci.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/tty/serial/sh-sci.c +8 -1
index cb3d5d37674f..060fcd42b6d5 100644
@@ -1936,7 +1936,7 @@ static int sci_request_irq(struct sci_port *port)
 
 static void sci_free_irq(struct sci_port *port)
 {
-	int i;
+	int i, j;
 
 	/*
 	 * Intentionally in reverse order so we iterate over the muxed
@@ -1952,6 +1952,13 @@ static void sci_free_irq(struct sci_port *port)
 		if (unlikely(irq < 0))
 			continue;
 
+		/* Check if already freed (irq was muxed) */
+		for (j = 0; j < i; j++)
+			if (port->irqs[j] == irq)
+				j = i + 1;
+		if (j > i)
+			continue;
+
 		free_irq(port->irqs[i], port);
 		kfree(port->irqstr[i]);
 
Signature · 1 line
2.16.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 6 lines · Chris Brandt

Since IRQs might be muxed on some parts, we need to pay attention when we are freeing them.
Otherwise we get the ugly WARNING "Trying to free already-free IRQ 20".

Fixes 628c534ae735 ("serial: sh-sci: Improve support for separate TEI and DRI interrupts")
Quoted 3 lines

---
v2:
* fix bad commit grammer

s/grammer/grammar/ :)

Quoted 34 lines
---
 drivers/tty/serial/sh-sci.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/tty/serial/sh-sci.c +8 -1
index cb3d5d37674f..060fcd42b6d5 100644
@@ -1936,7 +1936,7 @@ static int sci_request_irq(struct sci_port *port)
 
 static void sci_free_irq(struct sci_port *port)
 {
-	int i;
+	int i, j;
 
 	/*
 	 * Intentionally in reverse order so we iterate over the muxed
@@ -1952,6 +1952,13 @@ static void sci_free_irq(struct sci_port *port)
 		if (unlikely(irq < 0))
 			continue;
 
+		/* Check if already freed (irq was muxed) */
+		for (j = 0; j < i; j++)
+			if (port->irqs[j] == irq)
+				j = i + 1;
+		if (j > i)
+			continue;
+
 		free_irq(port->irqs[i], port);
 		kfree(port->irqstr[i]);
 
Signature · 1 line
2.16.1
Reviewed-by on v2 1/1
#2 lore raw
In reply to Chris Brandt

Hi Chris,

Quoted 8 lines · Chris Brandt

Since IRQs might be muxed on some parts, we need to pay attention when we are freeing them.
Otherwise we get the ugly WARNING "Trying to free already-free IRQ 20".

Fixes 628c534ae735 ("serial: sh-sci: Improve support for separate TEI and DRI interrupts")

---
v2:

Thanks for the update!

Quoted 6 lines
drivers/tty/serial/sh-sci.c +0 -0
@@ -1952,6 +1952,13 @@ static void sci_free_irq(struct sci_port *port)
                if (unlikely(irq < 0))
                        continue;

drivers/tty/serial/sh-sci.c static void sci_free_irq(struct sci_port *port) · line 1963

Quoted 10 lines
drivers/tty/serial/sh-sci.c +7 -0
 
+               /* Check if already freed (irq was muxed) */
+               for (j = 0; j < i; j++)
+                       if (port->irqs[j] == irq)
+                               j = i + 1;
+               if (j > i)
+                       continue;
+
                free_irq(port->irqs[i], port);
                kfree(port->irqstr[i]);

I think the error path in sci_request_irq() needs similar handling, also for SCIx_IRQ_IS_MUXED().

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds