[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a6b280993ac5448fa75f226262893f89@AcuMS.aculab.com>
Date: Sun, 28 Jan 2024 19:29:45 +0000
From: David Laight <David.Laight@...LAB.COM>
To: "'linux-kernel@...r.kernel.org'" <linux-kernel@...r.kernel.org>, "'Linus
Torvalds'" <torvalds@...ux-foundation.org>, 'Netdev'
<netdev@...r.kernel.org>, "'dri-devel@...ts.freedesktop.org'"
<dri-devel@...ts.freedesktop.org>
CC: 'Andy Shevchenko' <andriy.shevchenko@...ux.intel.com>, 'Andrew Morton'
<akpm@...ux-foundation.org>, "'Matthew Wilcox (Oracle)'"
<willy@...radead.org>, 'Christoph Hellwig' <hch@...radead.org>, "'Dan
Carpenter'" <dan.carpenter@...aro.org>, 'Linus Walleij'
<linus.walleij@...aro.org>, "'David S . Miller'" <davem@...emloft.net>,
"'linux-btrfs@...r.kernel.org'" <linux-btrfs@...r.kernel.org>, 'Jens Axboe'
<axboe@...nel.dk>
Subject: RE: [PATCH next 05/11] minmax: Move the signedness check out of
__cmp_once() and __clamp_once()
There is no need to do the signedness/type check when the arguments
are being cast to a fixed type.
So move the check out of __xxx_once() into __careful_xxx().
Signed-off-by: David Laight <david.laight@...lab.com>
---
include/linux/minmax.h | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/include/linux/minmax.h b/include/linux/minmax.h
index 8ee003d8abaf..111c52a14fe5 100644
--- a/include/linux/minmax.h
+++ b/include/linux/minmax.h
@@ -46,14 +46,14 @@
#define __cmp_once(op, x, y, uniq) ({ \
typeof(x) __x_##uniq = (x); \
typeof(y) __y_##uniq = (y); \
- _Static_assert(__types_ok(x, y), \
- #op "(" #x ", " #y ") signedness error, fix types or consider u" #op "() before " #op "_t()"); \
__cmp(op, __x_##uniq, __y_##uniq); })
#define __careful_cmp(op, x, y, uniq) \
__builtin_choose_expr(__is_constexpr((x) - (y)), \
__cmp(op, x, y), \
- __cmp_once(op, x, y, uniq))
+ ({ _Static_assert(__types_ok(x, y), \
+ #op "(" #x ", " #y ") signedness error, fix types or consider u" #op "() before " #op "_t()"); \
+ __cmp_once(op, x, y, uniq); }))
/**
* min - return minimum of two values of the same or compatible types
@@ -139,14 +139,14 @@
_Static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \
(lo) <= (hi), true), \
"clamp() low limit " #lo " greater than high limit " #hi); \
- _Static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error"); \
- _Static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error"); \
__clamp(__val_##uniq, __lo_##uniq, __hi_##uniq); })
-#define __careful_clamp(val, lo, hi, uniq) ({ \
+#define __careful_clamp(val, lo, hi, uniq) \
__builtin_choose_expr(__is_constexpr((val) - (lo) + (hi)), \
__clamp(val, lo, hi), \
- __clamp_once(val, lo, hi, uniq)); })
+ ({ _Static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error"); \
+ _Static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error"); \
+ __clamp_once(val, lo, hi, uniq); }))
/**
* clamp - return a value clamped to a given range with strict typechecking
--
2.17.1
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists