All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marek Behún" <kabel@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-serial@vger.kernel.org, "Pali Rohár" <pali@kernel.org>
Subject: Re: [PATCH 3/7] USB: serial: ftdi_sio: Extract SIO divisor code to function
Date: Thu, 7 Jul 2022 17:50:58 +0200	[thread overview]
Message-ID: <20220707175058.0b5e0b87@dellmb> (raw)
In-Reply-To: <Ysb3ORyUAPEOntqK@kroah.com>

On Thu, 7 Jul 2022 17:09:45 +0200
Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote:

> On Thu, Jul 07, 2022 at 04:53:50PM +0200, Marek Behún wrote:
> > From: Pali Rohár <pali@kernel.org>
> > 
> > As a code cleanup for future changes, extract divisor code for SIO chip
> > into new function ftdi_sio_baud_to_divisor().
> > 
> > No functional change.
> > 
> > Signed-off-by: Pali Rohár <pali@kernel.org>
> > Tested-by: Marek Behún <kabel@kernel.org>
> > ---
> >  drivers/usb/serial/ftdi_sio.c | 34 ++++++++++++++++++++--------------
> >  1 file changed, 20 insertions(+), 14 deletions(-)
> > 
> > diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
> > index 717b97f4e094..45a4eeb1fc70 100644
> > --- a/drivers/usb/serial/ftdi_sio.c
> > +++ b/drivers/usb/serial/ftdi_sio.c
> > @@ -1150,6 +1150,23 @@ static struct usb_serial_driver * const serial_drivers[] = {
> >   * ***************************************************************************
> >   */
> >  
> > +static u32 ftdi_sio_baud_to_divisor(int baud)
> > +{
> > +	switch (baud) {
> > +	case 300: return ftdi_sio_b300;
> > +	case 600: return ftdi_sio_b600;
> > +	case 1200: return ftdi_sio_b1200;
> > +	case 2400: return ftdi_sio_b2400;
> > +	case 4800: return ftdi_sio_b4800;
> > +	case 9600: return ftdi_sio_b9600;
> > +	case 19200: return ftdi_sio_b19200;
> > +	case 38400: return ftdi_sio_b38400;
> > +	case 57600: return ftdi_sio_b57600;
> > +	case 115200: return ftdi_sio_b115200;
> > +	default: return -1;  
> 
> Why not just return 9600 as a default here like the original code did?

It keeps at 9600 as original code.
Before:
  div_value = ftdi_sio_b9600;
  baud = 9600;

After:
  baud = 9600;
  div_value = ftdi_sio_baud_to_divisor(baud);

The new function that converts between the enum values and real values
now indicates when conversion is not possible.

> And returning a negative number for a u32 is not a good idea for the
> obvious reasons you found when you tried to test for it...

Would s32 be ok?

  reply	other threads:[~2022-07-07 15:51 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-07 14:53 [PATCH 0/7] ftdi_sio driver improvements Marek Behún
2022-07-07 14:53 ` [PATCH 1/7] USB: serial: ftdi_sio: Fix divisor overflow Marek Behún
2022-07-07 15:07   ` Greg Kroah-Hartman
2022-07-07 15:37     ` Marek Behún
2022-07-07 15:50       ` Greg Kroah-Hartman
2022-07-07 14:53 ` [PATCH 2/7] USB: serial: ftdi_sio: Add missing baudrate validation Marek Behún
2022-07-07 15:08   ` Greg Kroah-Hartman
2022-07-07 16:22     ` Marek Behún
2022-07-07 16:50       ` Greg Kroah-Hartman
2022-07-07 14:53 ` [PATCH 3/7] USB: serial: ftdi_sio: Extract SIO divisor code to function Marek Behún
2022-07-07 15:06   ` Greg Kroah-Hartman
2022-07-07 15:41     ` Marek Behún
2022-07-07 15:09   ` Greg Kroah-Hartman
2022-07-07 15:50     ` Marek Behún [this message]
2022-07-07 14:53 ` [PATCH 4/7] USB: serial: ftdi_sio: Do not reset baudrate to 9600 on error Marek Behún
2022-07-07 15:10   ` Greg Kroah-Hartman
2022-07-07 15:52     ` Marek Behún
2022-07-07 16:06       ` Greg Kroah-Hartman
2022-07-08 15:51   ` Andy Shevchenko
2022-07-12 11:28     ` m.brock
2022-07-12 12:09       ` Marek Behún
2022-07-12 12:11     ` Marek Behún
2022-07-07 14:53 ` [PATCH 5/7] USB: serial: ftdi_sio: Fix baudrate rounding for ASYNC_SPD_CUST Marek Behún
2022-07-07 15:11   ` Greg Kroah-Hartman
2022-07-07 16:08     ` Marek Behún
2022-07-07 16:12       ` Greg Kroah-Hartman
2022-07-07 14:53 ` [PATCH 6/7] USB: serial: ftdi_sio: Fix custom_divisor and c_*speed " Marek Behún
2022-07-07 14:53 ` [PATCH 7/7] USB: serial: ftdi_sio: Fill c_*speed fields with real baudrate Marek Behún
2022-07-07 15:11   ` Greg Kroah-Hartman
2022-07-07 15:07 ` [PATCH 0/7] ftdi_sio driver improvements 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=20220707175058.0b5e0b87@dellmb \
    --to=kabel@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=pali@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.