tools/include: Add _RET_IP_ and math definitions to kernel.h
authorKarolina Drobnik <karolinadrobnik@gmail.com>
Wed, 2 Feb 2022 11:03:02 +0000 (12:03 +0100)
committerMike Rapoport <rppt@linux.ibm.com>
Sun, 20 Feb 2022 06:44:37 +0000 (08:44 +0200)
Add max_t, min_t and clamp functions, together with _RET_IP_
definition, so they can be used in testing.

Signed-off-by: Karolina Drobnik <karolinadrobnik@gmail.com>
Signed-off-by: Mike Rapoport <rppt@kernel.org>
Link: https://lore.kernel.org/r/230fea382cb1e1659cdd52a55201854d38a0a149.1643796665.git.karolinadrobnik@gmail.com
tools/include/linux/kernel.h

index 9701e8307db02731b40e1ff886df4ac6bf93c002..4b0673bf52c2e615017bf2b94da1f6fc4392e532 100644 (file)
@@ -15,6 +15,8 @@
 #define UINT_MAX       (~0U)
 #endif
 
+#define _RET_IP_               ((unsigned long)__builtin_return_address(0))
+
 #define PERF_ALIGN(x, a)       __PERF_ALIGN_MASK(x, (typeof(x))(a)-1)
 #define __PERF_ALIGN_MASK(x, mask)     (((x)+(mask))&~(mask))
 
        _min1 < _min2 ? _min1 : _min2; })
 #endif
 
+#define max_t(type, x, y)      max((type)x, (type)y)
+#define min_t(type, x, y)      min((type)x, (type)y)
+#define clamp(val, lo, hi)     min((typeof(val))max(val, lo), hi)
+
 #ifndef BUG_ON
 #ifdef NDEBUG
 #define BUG_ON(cond) do { if (cond) {} } while (0)