Linux USB
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: Johan Hovold <johan@kernel.org>
Cc: "Marek Behún" <kabel@kernel.org>,
	linux-usb@vger.kernel.org,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>
Subject: Re: [PATCH v2 4/7] USB: serial: ftdi_sio: Do not reset baud rate to 9600 Baud on error
Date: Thu, 18 Aug 2022 16:12:54 +0200	[thread overview]
Message-ID: <20220818141254.4taurd2x6s273hda@pali> (raw)
In-Reply-To: <Yt05KkAwrkB0EnbN@hovoldconsulting.com>

On Sunday 24 July 2022 14:20:58 Johan Hovold wrote:
> On Tue, Jul 12, 2022 at 01:53:03PM +0200, Marek Behún wrote:
> > From: Pali Rohár <pali@kernel.org>
> > 
> > If setting new baud rate fails, all other drivers leave the device at
> > previous baud rate, only ftdi_sio resets to 9600 Baud.
> 
> > Change this behavior to that of other drivers so that /dev/ttyUSB*
> > devices behave in the same way.
> 
> These statements are not true. Several USB serial driver set 9600 baud
> on errors for historical reasons. Yet others clamp. It's inconsistent at
> best.
> 
> > Signed-off-by: Pali Rohár <pali@kernel.org>
> > Tested-by: Marek Behún <kabel@kernel.org>
> > Signed-off-by: Marek Behún <kabel@kernel.org>
> > ---
> > Greg pointed out that this make break some people's workflow, that they
> > may depend on this behavior.
> > 
> > This is of course possible, although IMO improbable: it would be weird
> > to depend on the fall back to 9600 Baud on error, instead of expecting
> > that the baud rate didn't change at all (like in other /dev/ttyUSB*
> > drivers).
> > 
> > Nonetheless if someone complains that they workflow got broken, we will
> > need to revert this.
> 
> >  static u32 get_ftdi_divisor(struct tty_struct *tty,
> > -						struct usb_serial_port *port)
> > +			    struct usb_serial_port *port, speed_t old_baud)
> >  {
> >  	struct ftdi_private *priv = usb_get_serial_port_data(port);
> >  	struct device *dev = &port->dev;
> > @@ -1322,6 +1322,8 @@ static u32 get_ftdi_divisor(struct tty_struct *tty,
> >  			__func__, priv->custom_divisor, baud);
> >  	}
> >  
> > +	if (!baud)
> > +		baud = old_baud;
> >  	if (!baud)
> >  		baud = 9600;
> 
> This looks like it breaks B0 handling. Either way, an unrelated change.

Unreleased to this change.

> >  	switch (priv->chip_type) {
> > @@ -1330,8 +1332,12 @@ static u32 get_ftdi_divisor(struct tty_struct *tty,
> >  		if (div_value == -1) {
> >  			dev_dbg(dev, "%s - Baudrate (%d) requested is not supported\n",
> >  				__func__,  baud);
> > -			baud = 9600;
> > +			baud = old_baud ? old_baud : 9600;
> >  			div_value = ftdi_sio_baud_to_divisor(baud);
> > +			if (div_value == -1) {
> > +				baud = 9600;
> > +				div_value = ftdi_sio_baud_to_divisor(baud);
> > +			}
> >  			div_okay = 0;
> >  		}
> >  		break;
> > @@ -1340,8 +1346,8 @@ static u32 get_ftdi_divisor(struct tty_struct *tty,
> >  			div_value = ftdi_232am_baud_to_divisor(baud);
> >  		} else {
> >  			dev_dbg(dev, "%s - Baud rate too high!\n", __func__);
> > -			baud = 9600;
> > -			div_value = ftdi_232am_baud_to_divisor(9600);
> > +			baud = (old_baud >= 183 && old_baud <= 3000000) ? old_baud : 9600;
> 
> And please avoid using the ternary operator which tend to just hurt
> readability.
> 
> Looks like this needs to be refactored in some way.
> 
> > @@ -1525,7 +1536,7 @@ static int set_serial_info(struct tty_struct *tty, struct serial_struct *ss)
> >  		if (priv->flags & ASYNC_SPD_MASK)
> >  			dev_warn_ratelimited(&port->dev, "use of SPD flags is deprecated\n");
> >  
> > -		change_speed(tty, port);
> > +		change_speed(tty, port, 0);
> 
> Zero has a special meaning (B0).
> 
> >  	}
> >  	mutex_unlock(&priv->cfg_lock);
> >  	return 0;
> > @@ -2774,9 +2785,12 @@ static void ftdi_set_termios(struct tty_struct *tty,
> >  		/* Drop RTS and DTR */
> >  		clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
> >  	} else {
> > +		speed_t old_baud =
> > +			old_termios ? tty_termios_baud_rate(old_termios) : 0;
> 
> Just use 9600 if you don't have an old termios. The termios rate should
> be valid in that case.

Ok

  reply	other threads:[~2022-08-18 14:13 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-12 11:52 [PATCH v2 0/7] ftdi_sio driver improvements Marek Behún
2022-07-12 11:53 ` [PATCH v2 1/7] USB: serial: ftdi_sio: Fix divisor overflow Marek Behún
2022-07-24 12:02   ` Johan Hovold
2022-07-12 11:53 ` [PATCH v2 2/7] USB: serial: ftdi_sio: Add missing baud rate validation Marek Behún
2022-07-12 17:27   ` Rob Pearce
2022-07-12 22:24     ` Marek Behún
2022-07-12 11:53 ` [PATCH v2 3/7] USB: serial: ftdi_sio: Extract SIO divisor code to function Marek Behún
2022-07-24 12:06   ` Johan Hovold
2022-08-18 14:11     ` Pali Rohár
2022-09-13 14:49       ` Johan Hovold
2022-09-13 15:30         ` Pali Rohár
2022-09-13 15:44           ` Johan Hovold
2022-07-12 11:53 ` [PATCH v2 4/7] USB: serial: ftdi_sio: Do not reset baud rate to 9600 Baud on error Marek Behún
2022-07-24 12:20   ` Johan Hovold
2022-08-18 14:12     ` Pali Rohár [this message]
2022-09-13 14:54       ` Johan Hovold
2022-07-12 11:53 ` [PATCH v2 5/7] USB: serial: ftdi_sio: Fix baud rate rounding for ASYNC_SPD_CUST Marek Behún
2022-07-24 12:26   ` Johan Hovold
2022-07-12 11:53 ` [PATCH v2 6/7] USB: serial: ftdi_sio: Fix custom_divisor and c_*speed " Marek Behún
2022-07-24 12:28   ` Johan Hovold
2022-07-24 12:33     ` Pali Rohár
2022-07-24 12:54       ` Johan Hovold
2022-07-24 12:59         ` Pali Rohár
2022-07-24 13:08           ` Johan Hovold
2022-08-18 14:09             ` Pali Rohár
2022-09-13 14:59               ` Johan Hovold
2022-09-14  8:48                 ` Pali Rohár
2022-09-14  8:58                   ` Johan Hovold
2022-09-14  9:10                     ` Pali Rohár
2022-09-14  9:18                       ` Johan Hovold
2022-09-14  9:20                         ` Pali Rohár
2022-07-12 11:53 ` [PATCH v2 7/7] USB: serial: ftdi_sio: Fill c_*speed fields with real baud rate Marek Behún
2022-07-24 12:41   ` Johan Hovold
2022-08-18 14:17     ` Pali Rohár
2022-09-13 15:02       ` Johan Hovold
2022-09-13 15:24         ` Pali Rohár
2022-09-13 15:34           ` Johan Hovold

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=20220818141254.4taurd2x6s273hda@pali \
    --to=pali@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan@kernel.org \
    --cc=kabel@kernel.org \
    --cc=linux-usb@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