]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
serial: use uart_port_ref_lock() helper
authorJiri Slaby (SUSE) <jirislaby@kernel.org>
Fri, 25 Apr 2025 11:13:14 +0000 (13:13 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 Apr 2025 11:46:31 +0000 (13:46 +0200)
uart_get_icount() and uart_carrier_raised() open code
uart_port_ref_lock(). Use the helper instead.

The difference is we use _irqsave() variants of a spinlock now. But
that's "safer" than _irq().

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/20250425111315.1036184-6-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/serial_core.c

index 52e764be42c454d930c77b83a8acb7e381d6116e..1f7708a91fc6d7238d0edbebd316811aba59263d 100644 (file)
@@ -1276,14 +1276,13 @@ static int uart_get_icount(struct tty_struct *tty,
        struct uart_state *state = tty->driver_data;
        struct uart_icount cnow;
        struct uart_port *uport;
+       unsigned long flags;
 
-       uport = uart_port_ref(state);
+       uport = uart_port_ref_lock(state, &flags);
        if (!uport)
                return -EIO;
-       uart_port_lock_irq(uport);
        memcpy(&cnow, &uport->icount, sizeof(struct uart_icount));
-       uart_port_unlock_irq(uport);
-       uart_port_deref(uport);
+       uart_port_unlock_deref(uport, flags);
 
        icount->cts         = cnow.cts;
        icount->dsr         = cnow.dsr;
@@ -1915,9 +1914,10 @@ static bool uart_carrier_raised(struct tty_port *port)
 {
        struct uart_state *state = container_of(port, struct uart_state, port);
        struct uart_port *uport;
+       unsigned long flags;
        int mctrl;
 
-       uport = uart_port_ref(state);
+       uport = uart_port_ref_lock(state, &flags);
        /*
         * Should never observe uport == NULL since checks for hangup should
         * abort the tty_port_block_til_ready() loop before checking for carrier
@@ -1926,11 +1926,9 @@ static bool uart_carrier_raised(struct tty_port *port)
         */
        if (WARN_ON(!uport))
                return true;
-       uart_port_lock_irq(uport);
        uart_enable_ms(uport);
        mctrl = uport->ops->get_mctrl(uport);
-       uart_port_unlock_irq(uport);
-       uart_port_deref(uport);
+       uart_port_unlock_deref(uport, flags);
 
        return mctrl & TIOCM_CAR;
 }