public inbox for linux-serial@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: gregkh@linuxfoundation.org
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jiri Slaby <jslaby@suse.cz>
Subject: [PATCH 04/19] mxser: move MSR read to mxser_check_modem_status()
Date: Thu, 18 Nov 2021 08:31:10 +0100	[thread overview]
Message-ID: <20211118073125.12283-5-jslaby@suse.cz> (raw)
In-Reply-To: <20211118073125.12283-1-jslaby@suse.cz>

The MSR read is currently performed on both places where
mxser_check_modem_status() is called. So move it there to avoid code
duplication.

Rename the variable to msr while we move it, to actually see what
"status" we are testing.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/mxser.c | 46 ++++++++++++++++++++++++---------------------
 1 file changed, 25 insertions(+), 21 deletions(-)

diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c
index c8a56b0d900d..3d5c20e31836 100644
--- a/drivers/tty/mxser.c
+++ b/drivers/tty/mxser.c
@@ -683,27 +683,34 @@ static void mxser_change_speed(struct tty_struct *tty, struct ktermios *old_term
 	outb(cval, info->ioaddr + UART_LCR);
 }
 
-static void mxser_check_modem_status(struct tty_struct *tty,
-				struct mxser_port *port, int status)
+static u8 mxser_check_modem_status(struct tty_struct *tty,
+				struct mxser_port *port)
 {
+	u8 msr = inb(port->ioaddr + UART_MSR);
+
+	if (!(msr & UART_MSR_ANY_DELTA))
+		return msr;
+
 	/* update input line counters */
-	if (status & UART_MSR_TERI)
+	if (msr & UART_MSR_TERI)
 		port->icount.rng++;
-	if (status & UART_MSR_DDSR)
+	if (msr & UART_MSR_DDSR)
 		port->icount.dsr++;
-	if (status & UART_MSR_DDCD)
+	if (msr & UART_MSR_DDCD)
 		port->icount.dcd++;
-	if (status & UART_MSR_DCTS)
+	if (msr & UART_MSR_DCTS)
 		port->icount.cts++;
 	wake_up_interruptible(&port->port.delta_msr_wait);
 
-	if (tty_port_check_carrier(&port->port) && (status & UART_MSR_DDCD)) {
-		if (status & UART_MSR_DCD)
+	if (tty_port_check_carrier(&port->port) && (msr & UART_MSR_DDCD)) {
+		if (msr & UART_MSR_DCD)
 			wake_up_interruptible(&port->port.open_wait);
 	}
 
 	if (tty_port_cts_enabled(&port->port))
-		mxser_handle_cts(tty, port, status);
+		mxser_handle_cts(tty, port, msr);
+
+	return msr;
 }
 
 static void mxser_disable_and_clear_FIFO(struct mxser_port *info)
@@ -1135,25 +1142,24 @@ static int mxser_get_lsr_info(struct mxser_port *info,
 static int mxser_tiocmget(struct tty_struct *tty)
 {
 	struct mxser_port *info = tty->driver_data;
-	unsigned char control, status;
+	unsigned char control;
 	unsigned long flags;
+	u8 msr;
 
 	if (tty_io_error(tty))
 		return -EIO;
 
 	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);
+	msr = mxser_check_modem_status(tty, info);
 	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) |
-		    ((status & UART_MSR_RI) ? TIOCM_RNG : 0) |
-		    ((status & UART_MSR_DSR) ? TIOCM_DSR : 0) |
-		    ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
+		    ((msr & UART_MSR_DCD) ? TIOCM_CAR : 0) |
+		    ((msr & UART_MSR_RI) ? TIOCM_RNG : 0) |
+		    ((msr & UART_MSR_DSR) ? TIOCM_DSR : 0) |
+		    ((msr & UART_MSR_CTS) ? TIOCM_CTS : 0);
 }
 
 static int mxser_tiocmset(struct tty_struct *tty,
@@ -1656,7 +1662,7 @@ static void mxser_transmit_chars(struct tty_struct *tty, struct mxser_port *port
 static bool mxser_port_isr(struct mxser_port *port)
 {
 	struct tty_struct *tty;
-	u8 iir, msr, status;
+	u8 iir, status;
 	bool error = false;
 
 	iir = inb(port->ioaddr + UART_IIR);
@@ -1689,9 +1695,7 @@ static bool mxser_port_isr(struct mxser_port *port)
 			status = mxser_receive_chars(tty, port, status);
 	}
 
-	msr = inb(port->ioaddr + UART_MSR);
-	if (msr & UART_MSR_ANY_DELTA)
-		mxser_check_modem_status(tty, port, msr);
+	mxser_check_modem_status(tty, port);
 
 	if (port->board->must_hwid) {
 		if (iir == 0x02 && (status & UART_LSR_THRE))
-- 
2.33.1


  parent reply	other threads:[~2021-11-18  7:31 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-18  7:31 [PATCH 00/19] mxser: another round of cleanups and fixes Jiri Slaby
2021-11-18  7:31 ` [PATCH 01/19] mxser: remove wait for sent from mxser_close_port Jiri Slaby
2021-11-18  7:31 ` [PATCH 02/19] mxser: rename mxser_close_port() to mxser_stop_rx() Jiri Slaby
2021-11-18  7:31 ` [PATCH 03/19] mxser: keep only !tty test in ISR Jiri Slaby
2021-11-18  7:31 ` Jiri Slaby [this message]
2021-11-18  7:31 ` [PATCH 05/19] mxser: clean up tx handling in mxser_transmit_chars() Jiri Slaby
2021-11-18  7:31 ` [PATCH 06/19] mxser: remove pointless xmit_buf checks Jiri Slaby
2021-11-18  7:31 ` [PATCH 07/19] mxser: remove tty->driver_data NULL check Jiri Slaby
2021-11-18  7:31 ` [PATCH 08/19] mxser: call stop_rx from mxser_shutdown_port() Jiri Slaby
2021-11-18  7:31 ` [PATCH 09/19] mxser: don't flush buffer from mxser_close() directly Jiri Slaby
2021-11-18  7:31 ` [PATCH 10/19] mxser: use tty_port_close() in mxser_close() Jiri Slaby
2021-11-18  7:31 ` [PATCH 11/19] mxser: extract TX empty check from mxser_wait_until_sent() Jiri Slaby
2021-11-18  7:31 ` [PATCH 12/19] mxser: use msleep_interruptible() in mxser_wait_until_sent() Jiri Slaby
2021-11-18  7:31 ` [PATCH 13/19] mxser: clean up timeout handling " Jiri Slaby
2021-11-18  7:31 ` [PATCH 14/19] mxser: don't throttle manually Jiri Slaby
2021-11-18  7:31 ` [PATCH 15/19] mxser: remove tty parameter from mxser_receive_chars_new() Jiri Slaby
2021-11-18  7:31 ` [PATCH 16/19] mxser: increase buf_overrun if tty_insert_flip_char() fails Jiri Slaby
2021-11-18  7:31 ` [PATCH 17/19] mxser: add MOXA prefix to some PCI device IDs Jiri Slaby
2021-11-18  7:31 ` [PATCH 18/19] mxser: move ids from pci_ids.h here Jiri Slaby
2021-11-18 20:58   ` Bjorn Helgaas
2021-11-18  7:31 ` [PATCH 19/19] mxser: use PCI_DEVICE_DATA Jiri Slaby

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211118073125.12283-5-jslaby@suse.cz \
    --to=jslaby@suse.cz \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox