serial: altera_uart: fix locking in polling mode
authorGabriel Somlo <gsomlo@gmail.com>
Tue, 22 Nov 2022 20:04:26 +0000 (15:04 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 23 Nov 2022 08:38:42 +0000 (09:38 +0100)
Since altera_uart_interrupt() may also be called from
a poll timer in "serving_softirq" context, use
spin_[lock_irqsave|unlock_irqrestore] variants, which
are appropriate for both softirq and hardware interrupt
contexts.

Fixes: 2f8b9c15cd88 ("altera_uart: Add support for polling mode (IRQ-less)")
Signed-off-by: Gabriel Somlo <gsomlo@gmail.com>
Link: https://lore.kernel.org/r/20221122200426.888349-1-gsomlo@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/altera_uart.c

index 316074bb23e9fb46d1c3cd66172ddf4ee4068296..9ce3d24af53600d6f458dd979969f0d69fe69ca4 100644 (file)
@@ -259,16 +259,17 @@ static irqreturn_t altera_uart_interrupt(int irq, void *data)
 {
        struct uart_port *port = data;
        struct altera_uart *pp = container_of(port, struct altera_uart, port);
+       unsigned long flags;
        unsigned int isr;
 
        isr = altera_uart_readl(port, ALTERA_UART_STATUS_REG) & pp->imr;
 
-       spin_lock(&port->lock);
+       spin_lock_irqsave(&port->lock, flags);
        if (isr & ALTERA_UART_STATUS_RRDY_MSK)
                altera_uart_rx_chars(port);
        if (isr & ALTERA_UART_STATUS_TRDY_MSK)
                altera_uart_tx_chars(port);
-       spin_unlock(&port->lock);
+       spin_unlock_irqrestore(&port->lock, flags);
 
        return IRQ_RETVAL(isr);
 }