Thread (1 message) 1 message, 1 author, 2018-10-12

Re: [PATCH] bitfield: use BUILD_BUG_ON_ZERO()

From: Johannes Berg <johannes@sipsolutions.net>
Date: 2018-10-12 19:45:20
Also in: lkml

Umm, I really should've tested this :-)

As John points out, it can't possibly compile, e.g. because
+#define __BF_FIELD_CHECK(_mask, _reg, _val)				\
+	BUILD_BUG_ON_ZERO(!__builtin_constant_p(_mask)) +		\
this isn't actually a constant expression.

This would be harmless, since e.g.
+	BUILD_BUG_ON_ZERO((_mask) == 0) +				\
this already forces _mask to be a constant, but
+	BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ?			\
+				~((_mask) >> __bf_shf(_mask)) & (_val) : 0) + \
we can't actually replicate this check.

We could just remove this as well, at the expense of not getting any
warnings if you write something like

	FIELD_PREP(0xf, 32);

Realistically, FIELD_PREP() is the only one that makes sense in a pure
constant context though, so we could just add __FIELD_PREP for that,
*with* all the checks. I'll send out a patch in a second that has this
and also adds __{u,le,be}{16,32,64}encode_bits().

johannes
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help