Messages in this thread | | | From | Roland Dreier <> | Subject | Re: [patch] Add helper macros for little-endian bitfields | Date | Sun, 24 Aug 2008 18:37:43 -0700 |
| |
> + * 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.
| |