Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mxser: use tty_port_tty guard() in mxser_port_isr()

Use scoped_guard() and reorder the function. This is done separately
from the other changes, as it is slighly more intrusive: scoped_guard()
handles the have-tty case and returns. The non-tty case is done at the
end of the function.

Signed-off-by: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/20250814072456.182853-7-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jiri Slaby (SUSE) and committed by
Greg Kroah-Hartman
81600e92 88d65e22

+32 -36
+32 -36
drivers/tty/mxser.c
··· 1600 1600 1601 1601 static bool mxser_port_isr(struct mxser_port *port) 1602 1602 { 1603 - struct tty_struct *tty; 1604 1603 u8 iir, status; 1605 - bool error = false; 1606 1604 1607 1605 iir = inb(port->ioaddr + UART_IIR); 1608 1606 if (iir & UART_IIR_NO_INT) 1609 1607 return true; 1610 1608 1611 1609 iir &= MOXA_MUST_IIR_MASK; 1612 - tty = tty_port_tty_get(&port->port); 1613 - if (!tty) { 1614 - status = inb(port->ioaddr + UART_LSR); 1615 - outb(port->FCR | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT, 1616 - port->ioaddr + UART_FCR); 1617 - inb(port->ioaddr + UART_MSR); 1618 1610 1619 - error = true; 1620 - goto put_tty; 1611 + scoped_guard(tty_port_tty, &port->port) { 1612 + struct tty_struct *tty = scoped_tty(); 1613 + 1614 + status = inb(port->ioaddr + UART_LSR); 1615 + 1616 + if (port->board->must_hwid) { 1617 + if (iir == MOXA_MUST_IIR_GDA || 1618 + iir == MOXA_MUST_IIR_RDA || 1619 + iir == MOXA_MUST_IIR_RTO || 1620 + iir == MOXA_MUST_IIR_LSR) 1621 + status = mxser_receive_chars(tty, port, status); 1622 + } else { 1623 + status &= port->read_status_mask; 1624 + if (status & UART_LSR_DR) 1625 + status = mxser_receive_chars(tty, port, status); 1626 + } 1627 + 1628 + mxser_check_modem_status(tty, port); 1629 + 1630 + if (port->board->must_hwid) { 1631 + if (iir == 0x02 && (status & UART_LSR_THRE)) 1632 + mxser_transmit_chars(tty, port); 1633 + } else { 1634 + if (status & UART_LSR_THRE) 1635 + mxser_transmit_chars(tty, port); 1636 + } 1637 + 1638 + return false; 1621 1639 } 1622 1640 1623 1641 status = inb(port->ioaddr + UART_LSR); 1642 + outb(port->FCR | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT, 1643 + port->ioaddr + UART_FCR); 1644 + inb(port->ioaddr + UART_MSR); 1624 1645 1625 - if (port->board->must_hwid) { 1626 - if (iir == MOXA_MUST_IIR_GDA || 1627 - iir == MOXA_MUST_IIR_RDA || 1628 - iir == MOXA_MUST_IIR_RTO || 1629 - iir == MOXA_MUST_IIR_LSR) 1630 - status = mxser_receive_chars(tty, port, status); 1631 - } else { 1632 - status &= port->read_status_mask; 1633 - if (status & UART_LSR_DR) 1634 - status = mxser_receive_chars(tty, port, status); 1635 - } 1636 - 1637 - mxser_check_modem_status(tty, port); 1638 - 1639 - if (port->board->must_hwid) { 1640 - if (iir == 0x02 && (status & UART_LSR_THRE)) 1641 - mxser_transmit_chars(tty, port); 1642 - } else { 1643 - if (status & UART_LSR_THRE) 1644 - mxser_transmit_chars(tty, port); 1645 - } 1646 - 1647 - put_tty: 1648 - tty_kref_put(tty); 1649 - 1650 - return error; 1646 + return true; 1651 1647 } 1652 1648 1653 1649 /*