]> git.baikalelectronics.ru Git - kernel.git/commit
bitfield: fix *_encode_bits()
authorJohannes Berg <johannes@sipsolutions.net>
Wed, 20 Jun 2018 06:58:28 +0000 (08:58 +0200)
committerKalle Valo <kvalo@codeaurora.org>
Wed, 27 Jun 2018 15:58:48 +0000 (18:58 +0300)
commitef7462680b7e0ac2aea9956ecdde2d9e489dafe8
treeaca184c2f1fae9c18e1eb192d9a9bc3de975bc31
parentcd7aea581e7d62436922c89b2a9b09dd652ec8ec
bitfield: fix *_encode_bits()

There's a bug in *_encode_bits() in using ~field_multiplier() for
the check whether or not the constant value fits into the field,
this is wrong and clearly ~field_mask() was intended. This was
triggering for me for both constant and non-constant values.

Additionally, make this case actually into an compile error.
Declaring the extern function that will never exist with just a
warning is pointless as then later we'll just get a link error.

While at it, also fix the indentation in those lines I'm touching.

Finally, as suggested by Andy Shevchenko, add some tests and for
that introduce also u8 helpers. The tests don't compile without
the fix, showing that it's necessary.

Fixes: ec638ca75a1a ("Add primitives for manipulating bitfields both in host- and fixed-endian.")
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
include/linux/bitfield.h