netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] bitfield.h: add FIELD_MAX() and field_max()
@ 2020-03-11  2:42 Alex Elder
  2020-04-01 17:35 ` Nick Desaulniers
  0 siblings, 1 reply; 11+ messages in thread
From: Alex Elder @ 2020-03-11  2:42 UTC (permalink / raw)
  To: David Miller, Jakub Kicinski
  Cc: Nathan Chancellor, Al Viro, Johannes Berg, Arnd Bergmann,
	Masahiro Yamada, Bjorn Andersson, netdev, linux-kernel

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>
---
v3: Rebased on latest netdev-next/master.

David, please take this into net-next as soon as possible.  When the
IPA code was merged the other day this prerequisite patch was not
included, and as a result the IPA driver fails to build.  Thank you.

  See: https://lkml.org/lkml/2020/3/10/1839

					-Alex

 include/linux/bitfield.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

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
@@ -55,6 +55,19 @@
 					      (1ULL << __bf_shf(_mask))); \
 	})
 
+/**
+ * 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
@@ -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)	\
 {									\
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-04-02  7:58 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-11  2:42 [PATCH v3] bitfield.h: add FIELD_MAX() and field_max() Alex Elder
2020-04-01 17:35 ` Nick Desaulniers
2020-04-01 18:24   ` Alex Elder
2020-04-01 19:13     ` Nick Desaulniers
2020-04-01 19:44       ` Alex Elder
2020-04-01 19:54         ` Nick Desaulniers
2020-04-01 20:21           ` Alex Elder
2020-04-01 22:26             ` Nick Desaulniers
2020-04-01 23:18               ` Alex Elder
2020-04-02  0:26                 ` Nick Desaulniers
2020-04-02  7:58                   ` Maxim Kuvyrkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).