[PATCH v2 06/16] bitfield: Remove some pointless casts

david.laight.linux@gmail.com posted 16 patches 1 day, 11 hours ago
[PATCH v2 06/16] bitfield: Remove some pointless casts
Posted by david.laight.linux@gmail.com 1 day, 11 hours ago
From: David Laight <david.laight.linux@gmail.com>

Now that _val is always large enough to hold _mask there is no need
to cast it before the shift left.

This also corrects the incorrect parenthesis in FIELD_FIT(),
unlikely to be a real problem.

For FIELD_GET() and FIELD_MAX() there is no point casting the
result of the shift to the type of mask.
Even if mask were char/short the value will immediately be promoted
to 'signed int' as soon as it is used.
All that is likely to happen is an extra and with 0xff.

Remove the associated extra (...) around __auto_type variable.

Signed-off-by: David Laight <david.laight.linux@gmail.com>
---
 include/linux/bitfield.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h
index c30120535680..f1859e28df5d 100644
--- a/include/linux/bitfield.h
+++ b/include/linux/bitfield.h
@@ -88,13 +88,13 @@
 #define __FIELD_PREP(mask, val, pfx)					\
 	({								\
 		__BF_FIELD_CHECK_MASK(mask, val, pfx);			\
-		((typeof(mask))(val) << __bf_shf(mask)) & (mask);	\
+		((val) << __bf_shf(mask)) & (mask);			\
 	})
 
 #define __FIELD_GET(mask, reg, pfx)					\
 	({								\
 		__BF_FIELD_CHECK_MASK(mask, 0U, pfx);			\
-		(typeof(mask))(((reg) & (mask)) >> __bf_shf(mask));	\
+		((reg) & (mask)) >> __bf_shf(mask);			\
 	})
 
 /**
@@ -108,7 +108,7 @@
 	({								\
 		__auto_type _mask = mask;				\
 		__BF_FIELD_CHECK(_mask, 0ULL, 0ULL, "FIELD_MAX: ");	\
-		(typeof(_mask))((_mask) >> __bf_shf(_mask));		\
+		(_mask >> __bf_shf(_mask));				\
 	})
 
 /**
@@ -123,7 +123,7 @@
 		__auto_type _mask = mask;				\
 		__auto_type _val = 1 ? (val) : _mask;			\
 		__BF_FIELD_CHECK(_mask, 0ULL, 0ULL, "FIELD_FIT: ");	\
-		!((((typeof(_mask))_val) << __bf_shf(_mask)) & ~(_mask)); \
+		!((_val << __bf_shf(_mask)) & ~_mask);			\
 	})
 
 /**
@@ -201,7 +201,7 @@
 		typecheck_pointer(_reg_p);						\
 		__BF_FIELD_CHECK(_mask, *(_reg_p), _val, "FIELD_MODIFY: ");		\
 		*(_reg_p) &= ~(_mask);							\
-		*(_reg_p) |= (((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask));	\
+		*(_reg_p) |= (_val << __bf_shf(_mask)) & _mask;				\
 	})
 
 extern void __compiletime_error("value doesn't fit into mask")
-- 
2.39.5