Skip to content

Commit e2b02d3

Browse files
benhor01YuryNorov
authored andcommitted
bitfield: Ensure the return values of helper functions are checked
As type##_replace_bits() has no side effects it is only useful if its return value is checked. Add __must_check to enforce this usage. To have the bits replaced in-place typep##_replace_bits() can be used instead. Although, type_##_get_bits() and type_##_encode_bits() are harder to misuse they are still only useful if the return value is checked. For consistency, also add __must_check to these. Signed-off-by: Ben Horgan <[email protected]> Signed-off-by: Yury Norov (NVIDIA) <[email protected]>
1 parent dcb23e1 commit e2b02d3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

include/linux/bitfield.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,14 @@ static __always_inline u64 field_mask(u64 field)
189189
}
190190
#define field_max(field) ((typeof(field))field_mask(field))
191191
#define ____MAKE_OP(type,base,to,from) \
192-
static __always_inline __##type type##_encode_bits(base v, base field) \
192+
static __always_inline __##type __must_check type##_encode_bits(base v, base field) \
193193
{ \
194194
if (__builtin_constant_p(v) && (v & ~field_mask(field))) \
195195
__field_overflow(); \
196196
return to((v & field_mask(field)) * field_multiplier(field)); \
197197
} \
198-
static __always_inline __##type type##_replace_bits(__##type old, \
199-
base val, base field) \
198+
static __always_inline __##type __must_check type##_replace_bits(__##type old, \
199+
base val, base field) \
200200
{ \
201201
return (old & ~to(field)) | type##_encode_bits(val, field); \
202202
} \
@@ -205,7 +205,7 @@ static __always_inline void type##p_replace_bits(__##type *p, \
205205
{ \
206206
*p = (*p & ~to(field)) | type##_encode_bits(val, field); \
207207
} \
208-
static __always_inline base type##_get_bits(__##type v, base field) \
208+
static __always_inline base __must_check type##_get_bits(__##type v, base field) \
209209
{ \
210210
return (from(v) & field)/field_multiplier(field); \
211211
}

0 commit comments

Comments
 (0)