[PATCH next 01/14] overflow: Reduce expansion of __type_max()

From: david . laight . linux

Date: Wed Jan 21 2026 - 10:46:03 EST


From: David Laight <david.laight.linux@xxxxxxxxx>

Change '(x - 1) + x' to '2 * (x - 1) + 1' to avoid expanding the
non-trivial __type_half_max() twice.

Signed-off-by: David Laight <david.laight.linux@xxxxxxxxx>
---
include/linux/overflow.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/overflow.h b/include/linux/overflow.h
index 736f633b2d5f..4f014d55ab25 100644
--- a/include/linux/overflow.h
+++ b/include/linux/overflow.h
@@ -31,7 +31,7 @@
* credit to Christian Biere.
*/
#define __type_half_max(type) ((type)1 << (8*sizeof(type) - 1 - is_signed_type(type)))
-#define __type_max(T) ((T)((__type_half_max(T) - 1) + __type_half_max(T)))
+#define __type_max(T) ((T)(2 * (__type_half_max(T) - 1) + 1))
#define type_max(t) __type_max(typeof(t))
#define __type_min(T) ((T)((T)-type_max(T)-(T)1))
#define type_min(t) __type_min(typeof(t))
--
2.39.5