lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sun, 01 Apr 2018 21:41:03 +0100
From:   David Howells <dhowells@...hat.com>
To:     linux-kernel@...r.kernel.org
Subject: [PATCH 08/45] C++: Implement abs() as an inline template function

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

Signed-off-by: David Howells <dhowells@...hat.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)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ