Merge tag 'at24-fixes-for-v5.14' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.git] / drivers / tty / mxser.c
index 54b9a9c..900ccb2 100644 (file)
@@ -398,6 +398,11 @@ static enum mxser_must_hwid mxser_must_get_hwid(unsigned long io)
        return MOXA_OTHER_UART;
 }
 
+static bool mxser_16550A_or_MUST(struct mxser_port *info)
+{
+       return info->type == PORT_16550A || info->board->must_hwid;
+}
+
 static void mxser_process_txrx_fifo(struct mxser_port *info)
 {
        unsigned int i;
@@ -537,8 +542,7 @@ static void mxser_handle_cts(struct tty_struct *tty, struct mxser_port *info,
                if (cts) {
                        tty->hw_stopped = 0;
 
-                       if (info->type != PORT_16550A &&
-                                       !info->board->must_hwid)
+                       if (!mxser_16550A_or_MUST(info))
                                __mxser_start_tx(info);
                        tty_wakeup(tty);
                }
@@ -547,7 +551,7 @@ static void mxser_handle_cts(struct tty_struct *tty, struct mxser_port *info,
                return;
 
        tty->hw_stopped = 1;
-       if (info->type != PORT_16550A && !info->board->must_hwid)
+       if (!mxser_16550A_or_MUST(info))
                __mxser_stop_tx(info);
 }
 
@@ -626,7 +630,7 @@ static void mxser_change_speed(struct tty_struct *tty)
        tty_port_set_cts_flow(&info->port, cflag & CRTSCTS);
        if (cflag & CRTSCTS) {
                info->IER |= UART_IER_MSI;
-               if ((info->type == PORT_16550A) || (info->board->must_hwid)) {
+               if (mxser_16550A_or_MUST(info)) {
                        info->MCR |= UART_MCR_AFE;
                } else {
                        mxser_handle_cts(tty, info,
@@ -962,11 +966,10 @@ static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int cou
                total += c;
        }
 
-       if (info->xmit_cnt && !tty->flow.stopped) {
-               if (!tty->hw_stopped || info->type == PORT_16550A ||
-                               info->board->must_hwid)
+       if (info->xmit_cnt && !tty->flow.stopped)
+               if (!tty->hw_stopped || mxser_16550A_or_MUST(info))
                        mxser_start_tx(info);
-       }
+
        return total;
 }
 
@@ -996,8 +999,7 @@ static void mxser_flush_chars(struct tty_struct *tty)
        struct mxser_port *info = tty->driver_data;
 
        if (!info->xmit_cnt || tty->flow.stopped || !info->port.xmit_buf ||
-                       (tty->hw_stopped && info->type != PORT_16550A &&
-                        !info->board->must_hwid))
+                       (tty->hw_stopped && !mxser_16550A_or_MUST(info)))
                return;
 
        mxser_start_tx(info);
@@ -1057,7 +1059,7 @@ static int mxser_set_serial_info(struct tty_struct *tty,
        struct tty_port *port = &info->port;
        speed_t baud;
        unsigned long sl_flags;
-       unsigned int flags, close_delay, closing_wait;
+       unsigned int old_speed, close_delay, closing_wait;
        int retval = 0;
 
        if (tty_io_error(tty))
@@ -1071,7 +1073,7 @@ static int mxser_set_serial_info(struct tty_struct *tty,
                return -EINVAL;
        }
 
-       flags = port->flags & ASYNC_SPD_MASK;
+       old_speed = port->flags & ASYNC_SPD_MASK;
 
        close_delay = msecs_to_jiffies(ss->close_delay * 10);
        closing_wait = ss->closing_wait;
@@ -1080,14 +1082,14 @@ static int mxser_set_serial_info(struct tty_struct *tty,
 
        if (!capable(CAP_SYS_ADMIN)) {
                if ((ss->baud_base != MXSER_BAUD_BASE) ||
-                               (close_delay != info->port.close_delay) ||
-                               (closing_wait != info->port.closing_wait) ||
-                               ((ss->flags & ~ASYNC_USR_MASK) != (info->port.flags & ~ASYNC_USR_MASK))) {
+                               (close_delay != port->close_delay) ||
+                               (closing_wait != port->closing_wait) ||
+                               ((ss->flags & ~ASYNC_USR_MASK) != (port->flags & ~ASYNC_USR_MASK))) {
                        mutex_unlock(&port->mutex);
                        return -EPERM;
                }
-               info->port.flags = ((info->port.flags & ~ASYNC_USR_MASK) |
-                               (ss->flags & ASYNC_USR_MASK));
+               port->flags = (port->flags & ~ASYNC_USR_MASK) |
+                               (ss->flags & ASYNC_USR_MASK);
        } else {
                /*
                 * OK, past this point, all the error checking has been done.
@@ -1115,7 +1117,7 @@ static int mxser_set_serial_info(struct tty_struct *tty,
        }
 
        if (tty_port_initialized(port)) {
-               if (flags != (port->flags & ASYNC_SPD_MASK)) {
+               if (old_speed != (port->flags & ASYNC_SPD_MASK)) {
                        spin_lock_irqsave(&info->slock, sl_flags);
                        mxser_change_speed(tty);
                        spin_unlock_irqrestore(&info->slock, sl_flags);
@@ -1162,13 +1164,13 @@ static int mxser_tiocmget(struct tty_struct *tty)
        if (tty_io_error(tty))
                return -EIO;
 
-       control = info->MCR;
-
        spin_lock_irqsave(&info->slock, flags);
+       control = info->MCR;
        status = inb(info->ioaddr + UART_MSR);
        if (status & UART_MSR_ANY_DELTA)
                mxser_check_modem_status(tty, info, status);
        spin_unlock_irqrestore(&info->slock, flags);
+
        return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0) |
                    ((control & UART_MCR_DTR) ? TIOCM_DTR : 0) |
                    ((status & UART_MSR_DCD) ? TIOCM_CAR : 0) |
@@ -1655,9 +1657,7 @@ static void mxser_transmit_chars(struct tty_struct *tty, struct mxser_port *port
                return;
 
        if (!port->xmit_cnt || tty->flow.stopped ||
-                       (tty->hw_stopped &&
-                       (port->type != PORT_16550A) &&
-                       (!port->board->must_hwid))) {
+                       (tty->hw_stopped && !mxser_16550A_or_MUST(port))) {
                __mxser_stop_tx(port);
                return;
        }