[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <adaprnxnac8.fsf@cisco.com>
Date: Sun, 24 Aug 2008 18:37:43 -0700
From: Roland Dreier <rdreier@...co.com>
To: David Vrabel <david.vrabel@....com>
Cc: Kernel development list <linux-kernel@...r.kernel.org>,
linux-usb <linux-usb@...r.kernel.org>,
torvalds@...ux-foundation.org
Subject: Re: [patch] Add helper macros for little-endian bitfields
> + * 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.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists