diff mbox series

[01/18] bitfield.h: add FIELD_MAX() and field_max()

Message ID 20190512012508.10608-2-elder@linaro.org
State Accepted
Commit e31a50162feb352147d3fc87b9e036703c8f2636
Headers show
Series net: introduce Qualcomm IPA driver | expand

Commit Message

Alex Elder May 12, 2019, 1:24 a.m. UTC
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>

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

-- 
2.20.1

Comments

Kalle Valo May 12, 2019, 6:33 a.m. UTC | #1
Alex Elder <elder@linaro.org> writes:

> 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>


Via which tree is this going? I assume I do not have take it unless
someone says otherwise.

-- 
Kalle Valo
Alex Elder May 12, 2019, 12:18 p.m. UTC | #2
On 5/12/19 1:33 AM, Kalle Valo wrote:
> Alex Elder <elder@linaro.org> writes:

> 

>> 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>

> 

> Via which tree is this going? I assume I do not have take it unless

> someone says otherwise.


Sorry about that, perhaps I should have posted it separately.

I don't have an answer, but we could avoid having to coordinate
if it went together with the rest.

					-Alex
Johannes Berg May 12, 2019, 7:30 p.m. UTC | #3
On Sun, 2019-05-12 at 07:18 -0500, Alex Elder wrote:
> On 5/12/19 1:33 AM, Kalle Valo wrote:

> > Alex Elder <elder@linaro.org> writes:

> > 

> > > 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>

> > 

> > Via which tree is this going? I assume I do not have take it unless

> > someone says otherwise.

> 

> Sorry about that, perhaps I should have posted it separately.

> 

> I don't have an answer, but we could avoid having to coordinate

> if it went together with the rest.


It's unlikely to conflict, and I don't think anyone really thinks that
the file is "theirs" (being basically standalone), so I think you should
just take it with whatever code that needs it.

johannes
diff mbox series

Patch

diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h
index 3f1ef4450a7c..cf4f06774520 100644
--- a/include/linux/bitfield.h
+++ b/include/linux/bitfield.h
@@ -63,6 +63,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
@@ -118,6 +131,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)	\
 {									\