summaryrefslogtreecommitdiff
path: root/include/linux/overflow-arith.h
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2015-10-23 02:49:41 -0700
committerDavid S. Miller <davem@davemloft.net>2015-10-23 02:49:41 -0700
commitec3661b42257d9a06cf0d318175623ac7a660113 (patch)
tree00351145ca8f839024370cf1909358845357bf3a /include/linux/overflow-arith.h
parentc80dbe04612986fd6104b4a1be21681b113b5ac9 (diff)
parentb72a2b01b686f242028038f630555513c9e4de38 (diff)
Merge branch 'ipv6-overflow-arith'
Hannes Frederic Sowa says: ==================== overflow-arith: begin to add support for overflow builtins functions I add a new header, linux/overflow-arith.h, as the central place to add overflow and wrap-around checking functions. The reason I am doing so is that it can make use of compiler supported builtin functions which can leverage hardware. As I need this for a fix in the ipv6 stack, which is also included in this series, I propose to add it sooner than later over Davem's net tree. This is also the reason why I start slowly with only the one function I need at this time. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux/overflow-arith.h')
-rw-r--r--include/linux/overflow-arith.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/include/linux/overflow-arith.h b/include/linux/overflow-arith.h
new file mode 100644
index 000000000000..e12ccf854a70
--- /dev/null
+++ b/include/linux/overflow-arith.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#include <linux/kernel.h>
+
+#ifdef CC_HAVE_BUILTIN_OVERFLOW
+
+#define overflow_usub __builtin_usub_overflow
+
+#else
+
+static inline bool overflow_usub(unsigned int a, unsigned int b,
+ unsigned int *res)
+{
+ *res = a - b;
+ return *res > a ? true : false;
+}
+
+#endif