From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Hurley Subject: Re: [RFC 3/4] tty: clean up port drain-delay handling Date: Wed, 13 Feb 2013 20:39:31 -0500 Message-ID: <1360805971.3385.27.camel@thor.lan> References: <20130213142513.GA21078@localhost> <1360776446-31371-1-git-send-email-jhovold@gmail.com> <1360776446-31371-4-git-send-email-jhovold@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Return-path: Received: from mailout01.c08.mtsvc.net ([205.186.168.189]:42708 "EHLO mailout01.c08.mtsvc.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753713Ab3BNBjm (ORCPT ); Wed, 13 Feb 2013 20:39:42 -0500 In-Reply-To: <1360776446-31371-4-git-send-email-jhovold@gmail.com> Sender: linux-serial-owner@vger.kernel.org List-Id: linux-serial@vger.kernel.org To: Johan Hovold Cc: Greg KH , Chris Ruehl , Alan Stern , Alan Cox , linux-usb@vger.kernel.org, linux-serial@vger.kernel.org, Alan Cox On Wed, 2013-02-13 at 18:27 +0100, Johan Hovold wrote: > Move port drain-delay handling to a separate function. > --- > drivers/tty/tty_port.c | 29 ++++++++++++++++++----------- > 1 file changed, 18 insertions(+), 11 deletions(-) > > diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c > index ffe3689..0a5e955 100644 > --- a/drivers/tty/tty_port.c > +++ b/drivers/tty/tty_port.c > @@ -407,6 +407,23 @@ int tty_port_block_til_ready(struct tty_port *port, > } > EXPORT_SYMBOL(tty_port_block_til_ready); > > +static void tty_port_drain_delay(struct tty_port *port, struct tty_struct *tty) > +{ > + unsigned int bps = tty_get_baud_rate(tty); > + long timeout; > + if (!port->drain_delay) > + return; ^^^^^^^^^^^^ How about drop this and ... > + if (bps > 1200) { > + timeout = (HZ * 10 * port->drain_delay) / bps; > + timeout = max_t(long, timeout, HZ / 10); > + } else { > + timeout = 2 * HZ; > + } > + schedule_timeout_interruptible(timeout); > +} > + > int tty_port_close_start(struct tty_port *port, > struct tty_struct *tty, struct file *filp) > { > @@ -445,17 +462,7 @@ int tty_port_close_start(struct tty_port *port, > if (test_bit(ASYNCB_INITIALIZED, &port->flags) && > port->closing_wait != ASYNC_CLOSING_WAIT_NONE) > tty_wait_until_sent_from_close(tty, port->closing_wait); > - if (port->drain_delay) { > - unsigned int bps = tty_get_baud_rate(tty); > - long timeout; > - > - if (bps > 1200) > - timeout = max_t(long, > - (HZ * 10 * port->drain_delay) / bps, HZ / 10); > - else > - timeout = 2 * HZ; > - schedule_timeout_interruptible(timeout); > - } > + tty_port_drain_delay(port, tty); .... if (port->drain_delay) tty_port_drain_delay(port, tty); > /* Flush the ldisc buffering */ > tty_ldisc_flush(tty); >