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 <ben.horgan@arm.com> Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>pull/1311/head
parent
dcb23e1878
commit
e2b02d382a
|
|
@ -189,14 +189,14 @@ static __always_inline u64 field_mask(u64 field)
|
||||||
}
|
}
|
||||||
#define field_max(field) ((typeof(field))field_mask(field))
|
#define field_max(field) ((typeof(field))field_mask(field))
|
||||||
#define ____MAKE_OP(type,base,to,from) \
|
#define ____MAKE_OP(type,base,to,from) \
|
||||||
static __always_inline __##type type##_encode_bits(base v, base field) \
|
static __always_inline __##type __must_check type##_encode_bits(base v, base field) \
|
||||||
{ \
|
{ \
|
||||||
if (__builtin_constant_p(v) && (v & ~field_mask(field))) \
|
if (__builtin_constant_p(v) && (v & ~field_mask(field))) \
|
||||||
__field_overflow(); \
|
__field_overflow(); \
|
||||||
return to((v & field_mask(field)) * field_multiplier(field)); \
|
return to((v & field_mask(field)) * field_multiplier(field)); \
|
||||||
} \
|
} \
|
||||||
static __always_inline __##type type##_replace_bits(__##type old, \
|
static __always_inline __##type __must_check type##_replace_bits(__##type old, \
|
||||||
base val, base field) \
|
base val, base field) \
|
||||||
{ \
|
{ \
|
||||||
return (old & ~to(field)) | type##_encode_bits(val, field); \
|
return (old & ~to(field)) | type##_encode_bits(val, field); \
|
||||||
} \
|
} \
|
||||||
|
|
@ -205,7 +205,7 @@ static __always_inline void type##p_replace_bits(__##type *p, \
|
||||||
{ \
|
{ \
|
||||||
*p = (*p & ~to(field)) | type##_encode_bits(val, field); \
|
*p = (*p & ~to(field)) | type##_encode_bits(val, field); \
|
||||||
} \
|
} \
|
||||||
static __always_inline base type##_get_bits(__##type v, base field) \
|
static __always_inline base __must_check type##_get_bits(__##type v, base field) \
|
||||||
{ \
|
{ \
|
||||||
return (from(v) & field)/field_multiplier(field); \
|
return (from(v) & field)/field_multiplier(field); \
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue