summaryrefslogtreecommitdiffstats
path: root/include/linux/bitfield.h
diff options
context:
space:
mode:
authorJakub Kicinski <jakub.kicinski@netronome.com>2017-02-09 12:17:27 -0500
committerDavid S. Miller <davem@davemloft.net>2017-02-10 15:52:24 -0500
commit1697599ee301a52cded6499a09bd609f7f63fd06 (patch)
treeb527e775e84e39aba8e6df205765ec441925e303 /include/linux/bitfield.h
parent4f2bd6b35b345523ac99b14ce9a1f4a98f21ebdb (diff)
bitfield.h: add FIELD_FIT() helper
Add a helper for checking at runtime that a value will fit inside a specified field/mask. Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux/bitfield.h')
-rw-r--r--include/linux/bitfield.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h
index f6505d83069d..8b9d6fff002d 100644
--- a/include/linux/bitfield.h
+++ b/include/linux/bitfield.h
@@ -63,6 +63,19 @@
63 }) 63 })
64 64
65/** 65/**
66 * FIELD_FIT() - check if value fits in the field
67 * @_mask: shifted mask defining the field's length and position
68 * @_val: value to test against the field
69 *
70 * Return: true if @_val can fit inside @_mask, false if @_val is too big.
71 */
72#define FIELD_FIT(_mask, _val) \
73 ({ \
74 __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_FIT: "); \
75 !((((typeof(_mask))_val) << __bf_shf(_mask)) & ~(_mask)); \
76 })
77
78/**
66 * FIELD_PREP() - prepare a bitfield element 79 * FIELD_PREP() - prepare a bitfield element
67 * @_mask: shifted mask defining the field's length and position 80 * @_mask: shifted mask defining the field's length and position
68 * @_val: value to put in the field 81 * @_val: value to put in the field