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.h: move all the clamp() definitions after the min/max() ones

At some point the definitions for clamp() got added in the middle of the
ones for min() and max(). Re-order the definitions so they are more
sensibly grouped.

Link: https://lkml.kernel.org/r/8bb285818e4846469121c8abc3dfb6e2@AcuMS.aculab.com
Signed-off-by: David Laight <david.laight@aculab.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Arnd Bergmann <arnd@kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Jason A. Donenfeld <Jason@zx2c4.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Mateusz Guzik <mjguzik@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Pedro Falcato <pedro.falcato@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

David Laight and committed by
Andrew Morton
c3939872 a5743f32

+62 -69
+62 -69
include/linux/minmax.h
··· 99 99 #define __careful_cmp(op, x, y) \ 100 100 __careful_cmp_once(op, x, y, __UNIQUE_ID(x_), __UNIQUE_ID(y_)) 101 101 102 - #define __clamp(val, lo, hi) \ 103 - ((val) >= (hi) ? (hi) : ((val) <= (lo) ? (lo) : (val))) 104 - 105 - #define __clamp_once(val, lo, hi, uval, ulo, uhi) ({ \ 106 - __auto_type uval = (val); \ 107 - __auto_type ulo = (lo); \ 108 - __auto_type uhi = (hi); \ 109 - BUILD_BUG_ON_MSG(statically_true(ulo > uhi), \ 110 - "clamp() low limit " #lo " greater than high limit " #hi); \ 111 - BUILD_BUG_ON_MSG(!__types_ok3(uval, ulo, uhi), \ 112 - "clamp("#val", "#lo", "#hi") signedness error"); \ 113 - __clamp(uval, ulo, uhi); }) 114 - 115 - #define __careful_clamp(val, lo, hi) \ 116 - __clamp_once(val, lo, hi, __UNIQUE_ID(v_), __UNIQUE_ID(l_), __UNIQUE_ID(h_)) 117 - 118 102 /** 119 103 * min - return minimum of two values of the same or compatible types 120 104 * @x: first value ··· 155 171 __careful_op3(max, x, y, z, __UNIQUE_ID(x_), __UNIQUE_ID(y_), __UNIQUE_ID(z_)) 156 172 157 173 /** 158 - * min_not_zero - return the minimum that is _not_ zero, unless both are zero 159 - * @x: value1 160 - * @y: value2 161 - */ 162 - #define min_not_zero(x, y) ({ \ 163 - typeof(x) __x = (x); \ 164 - typeof(y) __y = (y); \ 165 - __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); }) 166 - 167 - /** 168 - * clamp - return a value clamped to a given range with strict typechecking 169 - * @val: current value 170 - * @lo: lowest allowable value 171 - * @hi: highest allowable value 172 - * 173 - * This macro does strict typechecking of @lo/@hi to make sure they are of the 174 - * same type as @val. See the unnecessary pointer comparisons. 175 - */ 176 - #define clamp(val, lo, hi) __careful_clamp(val, lo, hi) 177 - 178 - /* 179 - * ..and if you can't take the strict 180 - * types, you can specify one yourself. 181 - * 182 - * Or not use min/max/clamp at all, of course. 183 - */ 184 - 185 - /** 186 174 * min_t - return minimum of two values, using the specified type 187 175 * @type: data type to use 188 176 * @x: first value ··· 169 213 * @y: second value 170 214 */ 171 215 #define max_t(type, x, y) __cmp_once(max, type, x, y) 216 + 217 + /** 218 + * min_not_zero - return the minimum that is _not_ zero, unless both are zero 219 + * @x: value1 220 + * @y: value2 221 + */ 222 + #define min_not_zero(x, y) ({ \ 223 + typeof(x) __x = (x); \ 224 + typeof(y) __y = (y); \ 225 + __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); }) 226 + 227 + #define __clamp(val, lo, hi) \ 228 + ((val) >= (hi) ? (hi) : ((val) <= (lo) ? (lo) : (val))) 229 + 230 + #define __clamp_once(val, lo, hi, uval, ulo, uhi) ({ \ 231 + __auto_type uval = (val); \ 232 + __auto_type ulo = (lo); \ 233 + __auto_type uhi = (hi); \ 234 + BUILD_BUG_ON_MSG(statically_true(ulo > uhi), \ 235 + "clamp() low limit " #lo " greater than high limit " #hi); \ 236 + BUILD_BUG_ON_MSG(!__types_ok3(uval, ulo, uhi), \ 237 + "clamp("#val", "#lo", "#hi") signedness error"); \ 238 + __clamp(uval, ulo, uhi); }) 239 + 240 + #define __careful_clamp(val, lo, hi) \ 241 + __clamp_once(val, lo, hi, __UNIQUE_ID(v_), __UNIQUE_ID(l_), __UNIQUE_ID(h_)) 242 + 243 + /** 244 + * clamp - return a value clamped to a given range with strict typechecking 245 + * @val: current value 246 + * @lo: lowest allowable value 247 + * @hi: highest allowable value 248 + * 249 + * This macro does strict typechecking of @lo/@hi to make sure they are of the 250 + * same type as @val. See the unnecessary pointer comparisons. 251 + */ 252 + #define clamp(val, lo, hi) __careful_clamp(val, lo, hi) 253 + 254 + /** 255 + * clamp_t - return a value clamped to a given range using a given type 256 + * @type: the type of variable to use 257 + * @val: current value 258 + * @lo: minimum allowable value 259 + * @hi: maximum allowable value 260 + * 261 + * This macro does no typechecking and uses temporary variables of type 262 + * @type to make all the comparisons. 263 + */ 264 + #define clamp_t(type, val, lo, hi) __careful_clamp((type)(val), (type)(lo), (type)(hi)) 265 + 266 + /** 267 + * clamp_val - return a value clamped to a given range using val's type 268 + * @val: current value 269 + * @lo: minimum allowable value 270 + * @hi: maximum allowable value 271 + * 272 + * This macro does no typechecking and uses temporary variables of whatever 273 + * type the input argument @val is. This is useful when @val is an unsigned 274 + * type and @lo and @hi are literals that will otherwise be assigned a signed 275 + * integer type. 276 + */ 277 + #define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi) 172 278 173 279 /* 174 280 * Do not check the array parameter using __must_be_array(). ··· 274 256 * Note that @len must not be zero (empty array). 275 257 */ 276 258 #define max_array(array, len) __minmax_array(max, array, len) 277 - 278 - /** 279 - * clamp_t - return a value clamped to a given range using a given type 280 - * @type: the type of variable to use 281 - * @val: current value 282 - * @lo: minimum allowable value 283 - * @hi: maximum allowable value 284 - * 285 - * This macro does no typechecking and uses temporary variables of type 286 - * @type to make all the comparisons. 287 - */ 288 - #define clamp_t(type, val, lo, hi) __careful_clamp((type)(val), (type)(lo), (type)(hi)) 289 - 290 - /** 291 - * clamp_val - return a value clamped to a given range using val's type 292 - * @val: current value 293 - * @lo: minimum allowable value 294 - * @hi: maximum allowable value 295 - * 296 - * This macro does no typechecking and uses temporary variables of whatever 297 - * type the input argument @val is. This is useful when @val is an unsigned 298 - * type and @lo and @hi are literals that will otherwise be assigned a signed 299 - * integer type. 300 - */ 301 - #define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi) 302 259 303 260 static inline bool in_range64(u64 val, u64 start, u64 len) 304 261 {