Re: [PATCH v2] add equivalent of BIT(x) for bitfields

From: Linus Torvalds
Date: Mon Dec 05 2016 - 13:23:10 EST


On Mon, Dec 5, 2016 at 9:49 AM, Sebastian Frias <sf84@xxxxxxxxxxx> wrote:
> Introduce GENVALUE(msb, lsb, value) macro to ease dealing with
> continuous bitfields, just as BIT(x) does for single bits.

Oh, and looking at the implementation, this is wrong. You use "lsb"
twice, so it mustn't have side effects.

That's fine for all expected users (since you'd expect that the only
real use of this is with constant values for msb/lsb), but please add
actual checking.

You can use BUILD_BUG_ON_ZERO(!__builtin_constant_p(x)) or something.
That returns zero, so it's easy to use in expressions.

Linus