lkml.org 
[lkml]   [2015]   [Nov]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2] USB: serial: cp210x: Add tx_empty()
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


\
 
 \ /
  Last update: 2015-11-26 08:41    [W:0.096 / U:1.348 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site