linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Konstantin Shkolnyy <Konstantin.Shkolnyy@silabs.com>
Cc: Johan Hovold <johan@kernel.org>,
	Konstantin Shkolnyy <konstantin.shkolnyy@gmail.com>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [EXT] Re: [PATCH RESEND 3/5] USB: serial: cp210x: Added comments to CRTSCT flag code.
Date: Thu, 28 Apr 2016 13:09:41 +0200	[thread overview]
Message-ID: <20160428110941.GS22229@localhost> (raw)
In-Reply-To: <BN3PR0701MB15740E60D5D5D3787138F2ED91640@BN3PR0701MB1574.namprd07.prod.outlook.com>

On Wed, Apr 27, 2016 at 08:06:32PM +0000, Konstantin Shkolnyy wrote:
> > -----Original Message-----
> > From: Johan Hovold [mailto:jhovold@gmail.com] On Behalf Of Johan Hovold
> > Sent: Tuesday, April 26, 2016 02:26
> > To: Konstantin Shkolnyy
> > Cc: Johan Hovold; Konstantin Shkolnyy; linux-usb@vger.kernel.org; linux-
> > kernel@vger.kernel.org
> > Subject: Re: [EXT] Re: [PATCH RESEND 3/5] USB: serial: cp210x: Added
> > comments to CRTSCT flag code.
> > 
> > On Mon, Apr 25, 2016 at 06:09:01PM +0000, Konstantin Shkolnyy wrote:
> > > I was planning to define all these bits in a separate future patch.
> > > Would you rather prefer the magic numbers defined before fixing the
> > bugs?
> > 
> > Fixing the RTS bug (patch 1), which is the only "real" bug, should be
> > done before adding defines, and fixing and cleaning up the rest.
> > 
> > > I guess I can do that. Is something like this acceptable?
> > >
> > > /* CP210X_GET_FLOW/CP210X_SET_FLOW read/write these 0x10 bytes */
> > > struct cp210x_flow_ctl {
> > > 	u8	SERIAL_DTR_MASK        : 2; /* byte 0 */
> > > 	u8	                       : 1;
> > > 	u8	SERIAL_CTS_HANDSHAKE   : 1;
> > > 	u8	SERIAL_DSR_HANDSHAKE   : 1;
> > > 	u8	SERIAL_DCD_HANDSHAKE   : 1;
> > > 	u8	SERIAL_DSR_SENSITIVITY : 1;
> > > 	u8	                       : 1;
> > > 	u8; /* byte 1 */
> > > 	u8; /* byte 2 */
> > > 	u8; /* byte 3 */
> > > 	u8	SERIAL_AUTO_TRANSMIT   : 1; /* byte 4 */
> > > 	u8	SERIAL_AUTO_RECEIVE    : 1;
> > > 	u8	SERIAL_ERROR_CHAR      : 1;
> > > 	u8	SERIAL_NULL_STRIPPING  : 1;
> > > 	u8	SERIAL_BREAK_CHAR      : 1;
> > > 	u8	                       : 1;
> > > 	u8	SERIAL_RTS_MASK        : 2;
> > > 	u8; /* byte 5 */
> > > 	u8; /* byte 6 */
> > > 	u8	                       : 7; /* byte 7 */
> > > 	u8	SERIAL_XOFF_CONTINUE   : 1;
> > > 	__le32	ulXonLimit;
> > > 	__le32	ulXoffLimit;
> > > } __packed;
> > 
> > No, shouldn't rely on the layout of bitfields. Define masks and shifts
> > as needed and the message structure as
> > 
> > struct cp210x_flow_ctl {
> > 	__le32	ulControlHandshake;
> > 	__le32	ulFlowReplace;
> >  	__le32	ulXonLimit;
> >  	__le32	ulXoffLimit;
> > };
> > 
> > that is, as per AN571.
> 
> OK, from searching www I see that bitfields have bad reputation for
> unclear reasons, so I guess it's now easier to avoid them.
> But doing it like you suggest, instead of splitting it to bytes, would
> complicate the code with endian conversions.
> Is there a reason for this other than making it identical to the spec?\

Staying aligned with the specification is usually a good idea. That also
became apparent when reviewing these patching and trying to match up the
magic constants with the spec.

The endian conversions should not need to complicate things that much.
Get the values using le32_to_cpu, manipulate the bits in a u32, and
store them back using cpu_to_le32.

Thanks,
Johan

      reply	other threads:[~2016-04-28 11:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-24 17:09 [PATCH RESEND 3/5] USB: serial: cp210x: Added comments to CRTSCT flag code Konstantin Shkolnyy
2016-04-25 10:16 ` Johan Hovold
2016-04-25 18:09   ` [EXT] " Konstantin Shkolnyy
2016-04-26  7:26     ` Johan Hovold
2016-04-27 20:06       ` Konstantin Shkolnyy
2016-04-28 11:09         ` Johan Hovold [this message]

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=20160428110941.GS22229@localhost \
    --to=johan@kernel.org \
    --cc=Konstantin.Shkolnyy@silabs.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;
as well as URLs for NNTP newsgroup(s).