diff options
Diffstat (limited to 'include/linux/bitfield.h')
| -rw-r--r-- | include/linux/bitfield.h | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h index cf2588d81148..3f1ef4450a7c 100644 --- a/include/linux/bitfield.h +++ b/include/linux/bitfield.h | |||
| @@ -53,7 +53,7 @@ | |||
| 53 | ({ \ | 53 | ({ \ |
| 54 | BUILD_BUG_ON_MSG(!__builtin_constant_p(_mask), \ | 54 | BUILD_BUG_ON_MSG(!__builtin_constant_p(_mask), \ |
| 55 | _pfx "mask is not constant"); \ | 55 | _pfx "mask is not constant"); \ |
| 56 | BUILD_BUG_ON_MSG(!(_mask), _pfx "mask is zero"); \ | 56 | BUILD_BUG_ON_MSG((_mask) == 0, _pfx "mask is zero"); \ |
| 57 | BUILD_BUG_ON_MSG(__builtin_constant_p(_val) ? \ | 57 | BUILD_BUG_ON_MSG(__builtin_constant_p(_val) ? \ |
| 58 | ~((_mask) >> __bf_shf(_mask)) & (_val) : 0, \ | 58 | ~((_mask) >> __bf_shf(_mask)) & (_val) : 0, \ |
| 59 | _pfx "value too large for the field"); \ | 59 | _pfx "value too large for the field"); \ |
| @@ -104,7 +104,7 @@ | |||
| 104 | (typeof(_mask))(((_reg) & (_mask)) >> __bf_shf(_mask)); \ | 104 | (typeof(_mask))(((_reg) & (_mask)) >> __bf_shf(_mask)); \ |
| 105 | }) | 105 | }) |
| 106 | 106 | ||
| 107 | extern void __compiletime_warning("value doesn't fit into mask") | 107 | extern void __compiletime_error("value doesn't fit into mask") |
| 108 | __field_overflow(void); | 108 | __field_overflow(void); |
| 109 | extern void __compiletime_error("bad bitfield mask") | 109 | extern void __compiletime_error("bad bitfield mask") |
| 110 | __bad_mask(void); | 110 | __bad_mask(void); |
| @@ -121,8 +121,8 @@ static __always_inline u64 field_mask(u64 field) | |||
| 121 | #define ____MAKE_OP(type,base,to,from) \ | 121 | #define ____MAKE_OP(type,base,to,from) \ |
| 122 | static __always_inline __##type type##_encode_bits(base v, base field) \ | 122 | static __always_inline __##type type##_encode_bits(base v, base field) \ |
| 123 | { \ | 123 | { \ |
| 124 | if (__builtin_constant_p(v) && (v & ~field_multiplier(field))) \ | 124 | if (__builtin_constant_p(v) && (v & ~field_mask(field))) \ |
| 125 | __field_overflow(); \ | 125 | __field_overflow(); \ |
| 126 | return to((v & field_mask(field)) * field_multiplier(field)); \ | 126 | return to((v & field_mask(field)) * field_multiplier(field)); \ |
| 127 | } \ | 127 | } \ |
| 128 | static __always_inline __##type type##_replace_bits(__##type old, \ | 128 | static __always_inline __##type type##_replace_bits(__##type old, \ |
| @@ -143,6 +143,7 @@ static __always_inline base type##_get_bits(__##type v, base field) \ | |||
| 143 | ____MAKE_OP(le##size,u##size,cpu_to_le##size,le##size##_to_cpu) \ | 143 | ____MAKE_OP(le##size,u##size,cpu_to_le##size,le##size##_to_cpu) \ |
| 144 | ____MAKE_OP(be##size,u##size,cpu_to_be##size,be##size##_to_cpu) \ | 144 | ____MAKE_OP(be##size,u##size,cpu_to_be##size,be##size##_to_cpu) \ |
| 145 | ____MAKE_OP(u##size,u##size,,) | 145 | ____MAKE_OP(u##size,u##size,,) |
| 146 | ____MAKE_OP(u8,u8,,) | ||
| 146 | __MAKE_OP(16) | 147 | __MAKE_OP(16) |
| 147 | __MAKE_OP(32) | 148 | __MAKE_OP(32) |
| 148 | __MAKE_OP(64) | 149 | __MAKE_OP(64) |
