public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Konstantin Shkolnyy <konstantin.shkolnyy@gmail.com>,
	johan@kernel.org, USB <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] USB: serial: cp210x: Add tx_empty()
Date: Thu, 26 Nov 2015 08:35:12 +0100	[thread overview]
Message-ID: <20151126073512.GD11484@localhost> (raw)
In-Reply-To: <CAHp75VcU5YeB3YMfk8JrmhJVjFCZ0ity6eACefkK1kQVTyJStQ@mail.gmail.com>

On Wed, Nov 25, 2015 at 10:26:12PM +0200, Andy Shevchenko wrote:
> On Wed, Nov 25, 2015 at 12:28 AM, Konstantin Shkolnyy
> <konstantin.shkolnyy@gmail.com> wrote:
> > Added tx_empty callback needed for generic wait-until-sent support.
> > Without this function, when the port is closed usbserial can't know that
> > there are still data in the chip's transmit FIFO. The chip gets disabled
> > and untransmitted data lost. When the actual byte count is reported by
> > tx-empty the close can be delayed until all data are sent.
> >
> 
> >  /*
> > + * Read how many bytes are waiting in the TX queue.
> > + */
> 
> One line?

Not necessarily for a function header.

> > +static bool cp210x_tx_empty(struct usb_serial_port *port)
> > +{
> > +       int err;
> > +       u32 count;
> > +
> > +       err = cp210x_get_tx_queue_byte_count(port, &count);
> 
> > +       if (!err && count)
> > +               return false;
> > +
> > +       return true;
> 
> return err || !count;

Nah, I don't consider that an improvement.

I prefer separating the error and success paths, for example:

	if (err)
		return true;

	return !count;

but the current code is also ok.

> Btw, can be count left uninitialized?

Yes, but that's not an issue. Clearly separating the success and errors
paths as I suggested above would make that more obvious however.

I'll fix that up before applying.

Thanks,
Johan

  reply	other threads:[~2015-11-26  7:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-24 22:28 [PATCH v2] USB: serial: cp210x: Add tx_empty() Konstantin Shkolnyy
2015-11-25 20:26 ` Andy Shevchenko
2015-11-26  7:35   ` Johan Hovold [this message]
2015-11-26  7:47     ` Johan Hovold
2015-11-26 16:14   ` Konstantin Shkolnyy

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=20151126073512.GD11484@localhost \
    --to=johan@kernel.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=konstantin.shkolnyy@gmail.com \
    --cc=linux-kernel@vger.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