summaryrefslogtreecommitdiff
path: root/include/linux/bitfield.h
diff options
context:
space:
mode:
authorAlex Elder <elder@linaro.org>2020-03-12 19:44:27 +0300
committerDavid S. Miller <davem@davemloft.net>2020-03-13 01:48:37 +0300
commite31a50162feb352147d3fc87b9e036703c8f2636 (patch)
treeefa42592a94ddb1b3cb2b62a8a1e6a903c914cbb /include/linux/bitfield.h
parent82a9822b26770b3965790f6a2340f0341a9bc102 (diff)
downloadlinux-e31a50162feb352147d3fc87b9e036703c8f2636.tar.xz
bitfield.h: add FIELD_MAX() and field_max()
Define FIELD_MAX(), which supplies the maximum value that can be represented by a field value. Define field_max() as well, to go along with the lower-case forms of the field mask functions. Signed-off-by: Alex Elder <elder@linaro.org> Acked-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux/bitfield.h')
-rw-r--r--include/linux/bitfield.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h
index 4bbb5f1c8b5b..48ea093ff04c 100644
--- a/include/linux/bitfield.h
+++ b/include/linux/bitfield.h
@@ -56,6 +56,19 @@
})
/**
+ * FIELD_MAX() - produce the maximum value representable by a field
+ * @_mask: shifted mask defining the field's length and position
+ *
+ * FIELD_MAX() returns the maximum value that can be held in the field
+ * specified by @_mask.
+ */
+#define FIELD_MAX(_mask) \
+ ({ \
+ __BF_FIELD_CHECK(_mask, 0ULL, 0ULL, "FIELD_MAX: "); \
+ (typeof(_mask))((_mask) >> __bf_shf(_mask)); \
+ })
+
+/**
* FIELD_FIT() - check if value fits in the field
* @_mask: shifted mask defining the field's length and position
* @_val: value to test against the field
@@ -110,6 +123,7 @@ static __always_inline u64 field_mask(u64 field)
{
return field / field_multiplier(field);
}
+#define field_max(field) ((typeof(field))field_mask(field))
#define ____MAKE_OP(type,base,to,from) \
static __always_inline __##type type##_encode_bits(base v, base field) \
{ \