diff options
author | Johannes Thumshirn <jthumshirn@suse.de> | 2015-08-06 03:16:37 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-08-14 20:14:13 -0400 |
commit | 8117e347406278fd399b077add4e638cd017ae2d (patch) | |
tree | c525404c5329e6d12f82dd5233687708b0a9cde2 | |
parent | 1d7002777a8fe8188caaa98d4a8eb4ed298fcdae (diff) |
tty: serial: men_z135_uart.c: Fix race between IRQ and set_termios()
Fix panic caused by a race between men_z135_intr() and men_z135_set_termios().
men_z135_intr() and men_z135_set_termios() both hold the struct uart_port::lock
spinlock, but men_z135_intr() does a spin_lock_irqsave() and
men_z135_set_termios() does a normal spin_lock(), which can lead to a deadlock
when an interrupt is called while the lock is being helt by
men_z135_set_termios().
This was discovered using a insmod, hardware looppback send/receive, rmmod
stress test.
Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: Peter Hurley <peter@hurleysoftware.com>
Cc: Andreas Werner <andreas.werner@men.de>
Cc: stable@vger.kernel.org # v4.0+
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/tty/serial/men_z135_uart.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/drivers/tty/serial/men_z135_uart.c b/drivers/tty/serial/men_z135_uart.c index 35c55505b3eb..5a41b8fbb10a 100644 --- a/drivers/tty/serial/men_z135_uart.c +++ b/drivers/tty/serial/men_z135_uart.c | |||
@@ -392,7 +392,6 @@ static irqreturn_t men_z135_intr(int irq, void *data) | |||
392 | struct men_z135_port *uart = (struct men_z135_port *)data; | 392 | struct men_z135_port *uart = (struct men_z135_port *)data; |
393 | struct uart_port *port = &uart->port; | 393 | struct uart_port *port = &uart->port; |
394 | bool handled = false; | 394 | bool handled = false; |
395 | unsigned long flags; | ||
396 | int irq_id; | 395 | int irq_id; |
397 | 396 | ||
398 | uart->stat_reg = ioread32(port->membase + MEN_Z135_STAT_REG); | 397 | uart->stat_reg = ioread32(port->membase + MEN_Z135_STAT_REG); |
@@ -401,7 +400,7 @@ static irqreturn_t men_z135_intr(int irq, void *data) | |||
401 | if (!irq_id) | 400 | if (!irq_id) |
402 | goto out; | 401 | goto out; |
403 | 402 | ||
404 | spin_lock_irqsave(&port->lock, flags); | 403 | spin_lock(&port->lock); |
405 | /* It's save to write to IIR[7:6] RXC[9:8] */ | 404 | /* It's save to write to IIR[7:6] RXC[9:8] */ |
406 | iowrite8(irq_id, port->membase + MEN_Z135_STAT_REG); | 405 | iowrite8(irq_id, port->membase + MEN_Z135_STAT_REG); |
407 | 406 | ||
@@ -427,7 +426,7 @@ static irqreturn_t men_z135_intr(int irq, void *data) | |||
427 | handled = true; | 426 | handled = true; |
428 | } | 427 | } |
429 | 428 | ||
430 | spin_unlock_irqrestore(&port->lock, flags); | 429 | spin_unlock(&port->lock); |
431 | out: | 430 | out: |
432 | return IRQ_RETVAL(handled); | 431 | return IRQ_RETVAL(handled); |
433 | } | 432 | } |
@@ -717,7 +716,7 @@ static void men_z135_set_termios(struct uart_port *port, | |||
717 | 716 | ||
718 | baud = uart_get_baud_rate(port, termios, old, 0, uart_freq / 16); | 717 | baud = uart_get_baud_rate(port, termios, old, 0, uart_freq / 16); |
719 | 718 | ||
720 | spin_lock(&port->lock); | 719 | spin_lock_irq(&port->lock); |
721 | if (tty_termios_baud_rate(termios)) | 720 | if (tty_termios_baud_rate(termios)) |
722 | tty_termios_encode_baud_rate(termios, baud, baud); | 721 | tty_termios_encode_baud_rate(termios, baud, baud); |
723 | 722 | ||
@@ -725,7 +724,7 @@ static void men_z135_set_termios(struct uart_port *port, | |||
725 | iowrite32(bd_reg, port->membase + MEN_Z135_BAUD_REG); | 724 | iowrite32(bd_reg, port->membase + MEN_Z135_BAUD_REG); |
726 | 725 | ||
727 | uart_update_timeout(port, termios->c_cflag, baud); | 726 | uart_update_timeout(port, termios->c_cflag, baud); |
728 | spin_unlock(&port->lock); | 727 | spin_unlock_irq(&port->lock); |
729 | } | 728 | } |
730 | 729 | ||
731 | static const char *men_z135_type(struct uart_port *port) | 730 | static const char *men_z135_type(struct uart_port *port) |