Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

bits: introduce fixed-type BIT_U*()

Implement fixed-type BIT_U*() to help drivers add stricter checks,
like it was done for GENMASK_U*().

Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Acked-by: Jani Nikula <jani.nikula@intel.com>
Co-developed-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Yury Norov <yury.norov@gmail.com>

authored by

Lucas De Marchi and committed by
Yury Norov
5b572e8a 19408200

+19 -1
+19 -1
include/linux/bits.h
··· 24 24 /* 25 25 * Missing asm support 26 26 * 27 - * GENMASK_U*() depend on BITS_PER_TYPE() which relies on sizeof(), 27 + * GENMASK_U*() and BIT_U*() depend on BITS_PER_TYPE() which relies on sizeof(), 28 28 * something not available in asm. Nevertheless, fixed width integers is a C 29 29 * concept. Assembly code can rely on the long and long long versions instead. 30 30 */ ··· 54 54 #define GENMASK_U16(h, l) GENMASK_TYPE(u16, h, l) 55 55 #define GENMASK_U32(h, l) GENMASK_TYPE(u32, h, l) 56 56 #define GENMASK_U64(h, l) GENMASK_TYPE(u64, h, l) 57 + 58 + /* 59 + * Fixed-type variants of BIT(), with additional checks like GENMASK_TYPE(). The 60 + * following examples generate compiler warnings due to -Wshift-count-overflow: 61 + * 62 + * - BIT_U8(8) 63 + * - BIT_U32(-1) 64 + * - BIT_U32(40) 65 + */ 66 + #define BIT_INPUT_CHECK(type, nr) \ 67 + BUILD_BUG_ON_ZERO(const_true((nr) >= BITS_PER_TYPE(type))) 68 + 69 + #define BIT_TYPE(type, nr) ((type)(BIT_INPUT_CHECK(type, nr) + BIT_ULL(nr))) 70 + 71 + #define BIT_U8(nr) BIT_TYPE(u8, nr) 72 + #define BIT_U16(nr) BIT_TYPE(u16, nr) 73 + #define BIT_U32(nr) BIT_TYPE(u32, nr) 74 + #define BIT_U64(nr) BIT_TYPE(u64, nr) 57 75 58 76 #else /* defined(__ASSEMBLY__) */ 59 77