public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Roland Dreier <rdreier@cisco.com>
To: David Vrabel <david.vrabel@csr.com>
Cc: Kernel development list <linux-kernel@vger.kernel.org>,
	linux-usb <linux-usb@vger.kernel.org>,
	torvalds@linux-foundation.org
Subject: Re: [patch] Add helper macros for little-endian bitfields
Date: Sun, 24 Aug 2008 18:37:43 -0700	[thread overview]
Message-ID: <adaprnxnac8.fsf@cisco.com> (raw)
In-Reply-To: <48AD6B93.7020702@csr.com> (David Vrabel's message of "Thu, 21 Aug 2008 14:20:19 +0100")

 > + * NOTE: When using multibyte bitfields, you need to convert the data
 > + *       from Little Endian to CPU before you can access the bitfield
 > + *       (to make it simpler):
 > + *
 > + *       union something {
 > + *               le16 value;
 > + *               DECL_BF_LE3(
 > + *                       u16  bf0:3,
 > + *                       u16  bf1:10,
 > + *                       u16  bf2:3
 > + *               ) __attribute__((packed));
 > + *       };
 > + *
 > + *       ...
 > + *
 > + *       union something s;
 > + *
 > + *       s.value = le16_to_cpu(something LE read from hw);
 > + *       frame_count = s.bf1;

I can't help thinking there's got to be a better way to do this... in
particular having 16 DECL_BF_LEnn() macros (and needing to count the
number of members every time you use one) is not particularly pretty.

In general the consensus with kernel code seems to be that you're better
off avoiding bitfields in structures, and just using shift/mask
operations to get at the data (with helper functions as needed).

However all of that is said without actually looking at the driver code
that uses this.

 - R.

  reply	other threads:[~2008-08-25  1:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-21 13:17 New subsystems: Ultra-Wideband radio, Wireless USB and WiMedia LLC Protocol David Vrabel
2008-08-21 13:19 ` [patch] bitmap: add bitmap_copy_le() David Vrabel
2008-08-21 13:20 ` [patch] Add helper macros for little-endian bitfields David Vrabel
2008-08-25  1:37   ` Roland Dreier [this message]
2008-08-25  1:43     ` Al Viro
2008-08-27 15:20       ` David Vrabel
2008-08-27 21:19         ` Jeremy Fitzhardinge
2008-08-27 21:26         ` Linus Torvalds
2008-08-21 14:21 ` New subsystems: Ultra-Wideband radio, Wireless USB and WiMedia LLC Protocol Sam Ravnborg
2008-08-21 19:01   ` Sam Ravnborg
2008-08-21 15:43 ` Greg KH
2008-09-17 16:20 ` David Vrabel

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=adaprnxnac8.fsf@cisco.com \
    --to=rdreier@cisco.com \
    --cc=david.vrabel@csr.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=torvalds@linux-foundation.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