Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

minmax: simplify and clarify min_t()/max_t() implementation

This simplifies the min_t() and max_t() macros by no longer making them
work in the context of a C constant expression.

That means that you can no longer use them for static initializers or
for array sizes in type definitions, but there were only a couple of
such uses, and all of them were converted (famous last words) to use
MIN_T/MAX_T instead.

Cc: David Laight <David.Laight@aculab.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

+11 -8
+11 -8
include/linux/minmax.h
··· 45 45 46 46 #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y)) 47 47 48 - #define __cmp_once(op, x, y, unique_x, unique_y) ({ \ 49 - typeof(x) unique_x = (x); \ 50 - typeof(y) unique_y = (y); \ 48 + #define __cmp_once_unique(op, type, x, y, ux, uy) \ 49 + ({ type ux = (x); type uy = (y); __cmp(op, ux, uy); }) 50 + 51 + #define __cmp_once(op, type, x, y) \ 52 + __cmp_once_unique(op, type, x, y, __UNIQUE_ID(x_), __UNIQUE_ID(y_)) 53 + 54 + #define __careful_cmp_once(op, x, y) ({ \ 51 55 static_assert(__types_ok(x, y), \ 52 56 #op "(" #x ", " #y ") signedness error, fix types or consider u" #op "() before " #op "_t()"); \ 53 - __cmp(op, unique_x, unique_y); }) 57 + __cmp_once(op, __auto_type, x, y); }) 54 58 55 59 #define __careful_cmp(op, x, y) \ 56 60 __builtin_choose_expr(__is_constexpr((x) - (y)), \ 57 - __cmp(op, x, y), \ 58 - __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) 61 + __cmp(op, x, y), __careful_cmp_once(op, x, y)) 59 62 60 63 #define __clamp(val, lo, hi) \ 61 64 ((val) >= (hi) ? (hi) : ((val) <= (lo) ? (lo) : (val))) ··· 161 158 * @x: first value 162 159 * @y: second value 163 160 */ 164 - #define min_t(type, x, y) __careful_cmp(min, (type)(x), (type)(y)) 161 + #define min_t(type, x, y) __cmp_once(min, type, x, y) 165 162 166 163 /** 167 164 * max_t - return maximum of two values, using the specified type ··· 169 166 * @x: first value 170 167 * @y: second value 171 168 */ 172 - #define max_t(type, x, y) __careful_cmp(max, (type)(x), (type)(y)) 169 + #define max_t(type, x, y) __cmp_once(max, type, x, y) 173 170 174 171 /* 175 172 * Do not check the array parameter using __must_be_array().