Implement abs() as an C++ inline template function as that greatly
simplifies the source.

Signed-off-by: David Howells <dhowe...@redhat.com>
---

 include/linux/kernel.h |   19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index e779a7487c34..59089f76c7d8 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -246,20 +246,11 @@ extern int _cond_resched(void);
  *
  * Return: an absolute value of x.
  */
-#define abs(x) __abs_choose_expr(x, long long,                         \
-               __abs_choose_expr(x, long,                              \
-               __abs_choose_expr(x, int,                               \
-               __abs_choose_expr(x, short,                             \
-               __abs_choose_expr(x, char,                              \
-               __builtin_choose_expr(                                  \
-                       __builtin_types_compatible_p(typeof(x), char),  \
-                       (char)({ signed char __x = (x); __x<0?-__x:__x; }), \
-                       ((void)0)))))))
-
-#define __abs_choose_expr(x, type, other) __builtin_choose_expr(       \
-       __builtin_types_compatible_p(typeof(x),   signed type) ||       \
-       __builtin_types_compatible_p(typeof(x), unsigned type),         \
-       ({ signed type __x = (x); __x < 0 ? -__x : __x; }), other)
+template<typename T>
+static inline T abs(T v)
+{
+       return v < 0 ? -v : v;
+}
 
 /**
  * reciprocal_scale - "scale" a value into range [0, ep_ro)

Reply via email to