linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jirislaby@kernel.org>,
	linux-staging@lists.linux.dev, greybus-dev@lists.linaro.org,
	linux-kernel@vger.kernel.org, Johan Hovold <johan@kernel.org>
Subject: [PATCH 09/16] tty: amiserial: add missing TIOCSSERIAL jiffies conversions
Date: Wed,  7 Apr 2021 12:23:27 +0200	[thread overview]
Message-ID: <20210407102334.32361-10-johan@kernel.org> (raw)
In-Reply-To: <20210407102334.32361-1-johan@kernel.org>

The tty-port close_delay and closing_wait parameters set by TIOCSSERIAL
are specified in jiffies, while the values returned by TIOCGSERIAL are
specified in centiseconds.

Add the missing conversions so that TIOCSSERIAL works as expected also
if this code is ever reused on a system where HZ is not 100.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/tty/amiserial.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
index ec6802ba2bf8..ca48ce5a0862 100644
--- a/drivers/tty/amiserial.c
+++ b/drivers/tty/amiserial.c
@@ -937,15 +937,21 @@ static void rs_unthrottle(struct tty_struct * tty)
 static int get_serial_info(struct tty_struct *tty, struct serial_struct *ss)
 {
 	struct serial_state *state = tty->driver_data;
+	unsigned int close_delay, closing_wait;
 
 	tty_lock(tty);
+	close_delay = jiffies_to_msecs(state->tport.close_delay) / 10;
+	closing_wait = state->tport.closing_wait;
+	if (closing_wait != ASYNC_CLOSING_WAIT_NONE)
+		closing_wait = jiffies_to_msecs(closing_wait) / 10;
+
 	ss->line = tty->index;
 	ss->port = state->port;
 	ss->flags = state->tport.flags;
 	ss->xmit_fifo_size = state->xmit_fifo_size;
 	ss->baud_base = state->baud_base;
-	ss->close_delay = state->tport.close_delay;
-	ss->closing_wait = state->tport.closing_wait;
+	ss->close_delay = close_delay;
+	ss->closing_wait = closing_wait;
 	ss->custom_divisor = state->custom_divisor;
 	tty_unlock(tty);
 	return 0;
@@ -957,6 +963,7 @@ static int set_serial_info(struct tty_struct *tty, struct serial_struct *ss)
 	struct tty_port *port = &state->tport;
 	bool change_spd;
 	int 			retval = 0;
+	unsigned int close_delay, closing_wait;
 
 	tty_lock(tty);
 	change_spd = ((ss->flags ^ port->flags) & ASYNC_SPD_MASK) ||
@@ -966,11 +973,16 @@ static int set_serial_info(struct tty_struct *tty, struct serial_struct *ss)
 		tty_unlock(tty);
 		return -EINVAL;
 	}
-  
+
+	close_delay = msecs_to_jiffies(ss->close_delay * 10);
+	closing_wait = ss->closing_wait;
+	if (closing_wait != ASYNC_CLOSING_WAIT_NONE)
+		closing_wait = msecs_to_jiffies(closing_wait * 10);
+
 	if (!serial_isroot()) {
 		if ((ss->baud_base != state->baud_base) ||
-		    (ss->close_delay != port->close_delay) ||
-		    (ss->closing_wait != port->closing_wait) ||
+		    (close_delay != port->close_delay) ||
+		    (closing_wait != port->closing_wait) ||
 		    (ss->xmit_fifo_size != state->xmit_fifo_size) ||
 		    ((ss->flags & ~ASYNC_USR_MASK) !=
 		     (port->flags & ~ASYNC_USR_MASK))) {
@@ -997,8 +1009,8 @@ static int set_serial_info(struct tty_struct *tty, struct serial_struct *ss)
 	port->flags = ((port->flags & ~ASYNC_FLAGS) |
 			(ss->flags & ASYNC_FLAGS));
 	state->custom_divisor = ss->custom_divisor;
-	port->close_delay = ss->close_delay * HZ/100;
-	port->closing_wait = ss->closing_wait * HZ/100;
+	port->close_delay = close_delay;
+	port->closing_wait = closing_wait;
 
 check_and_exit:
 	if (tty_port_initialized(port)) {
-- 
2.26.3


  parent reply	other threads:[~2021-04-07 10:24 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-07 10:23 [PATCH 00/16] tty: TIOCSSERIAL fixes and clean ups Johan Hovold
2021-04-07 10:23 ` [PATCH 01/16] staging: fwserial: fix TIOCSSERIAL jiffies conversions Johan Hovold
2021-04-07 10:23 ` [PATCH 02/16] staging: fwserial: fix TIOCSSERIAL permission check Johan Hovold
2021-04-07 10:23 ` [PATCH 03/16] staging: fwserial: fix TIOCSSERIAL implementation Johan Hovold
2021-04-07 10:23 ` [PATCH 04/16] staging: fwserial: fix TIOCGSERIAL implementation Johan Hovold
2021-04-07 10:23 ` [PATCH 05/16] staging: greybus: uart: fix TIOCSSERIAL jiffies conversions Johan Hovold
2021-04-07 10:23 ` [PATCH 06/16] staging: greybus: uart: fix unprivileged TIOCCSERIAL Johan Hovold
2021-04-07 10:23 ` [PATCH 07/16] staging: greybus: uart: clean up TIOCGSERIAL Johan Hovold
2021-04-07 10:23 ` [PATCH 08/16] tty: amiserial: fix TIOCSSERIAL permission check Johan Hovold
2021-04-07 10:23 ` Johan Hovold [this message]
2021-04-07 10:23 ` [PATCH 10/16] tty: moxa: fix TIOCSSERIAL jiffies conversions Johan Hovold
2021-04-07 10:23 ` [PATCH 11/16] tty: moxa: fix TIOCSSERIAL permission check Johan Hovold
2021-04-07 10:23 ` [PATCH 12/16] tty: moxa: fix TIOCSSERIAL implementation Johan Hovold
2021-04-07 10:23 ` [PATCH 13/16] tty: mxser: fix TIOCSSERIAL jiffies conversions Johan Hovold
2021-04-07 10:23 ` [PATCH 14/16] tty: mxser: fix TIOCSSERIAL permission check Johan Hovold
2021-04-07 10:23 ` [PATCH 15/16] pcmcia: synclink_cs: drop redundant tty-port initialisation Johan Hovold
2021-04-07 10:23 ` [PATCH 16/16] tty: synclink_gt: " Johan Hovold
2021-04-07 15:22 ` [PATCH 00/16] tty: TIOCSSERIAL fixes and clean ups Greg Kroah-Hartman

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=20210407102334.32361-10-johan@kernel.org \
    --to=johan@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=greybus-dev@lists.linaro.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    /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;
as well as URLs for NNTP newsgroup(s).