summaryrefslogtreecommitdiff
path: root/include/linux/kernel.h
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2018-12-19 20:03:16 +0900
committerMasahiro Yamada <yamada.masahiro@socionext.com>2018-12-29 11:38:36 +0900
commitb32aa9ebc57b8db5052e3b97dc5a3349cd91636b (patch)
tree45bfd562e35e026d3485c9ff87fdea5c2b757359 /include/linux/kernel.h
parentce480791f74859b6bac9327ee8083cb3c698d0e9 (diff)
linux/kernel.h: import DIV_ROUND_CLOSEST_ULL from Linux
Copied from Linux v4.20-rc7. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Diffstat (limited to 'include/linux/kernel.h')
-rw-r--r--include/linux/kernel.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index bd88483b9f..a85c15d8dc 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -102,6 +102,18 @@
(((__x) - ((__d) / 2)) / (__d)); \
} \
)
+/*
+ * Same as above but for u64 dividends. divisor must be a 32-bit
+ * number.
+ */
+#define DIV_ROUND_CLOSEST_ULL(x, divisor)( \
+{ \
+ typeof(divisor) __d = divisor; \
+ unsigned long long _tmp = (x) + (__d) / 2; \
+ do_div(_tmp, __d); \
+ _tmp; \
+} \
+)
/*
* Multiplies an integer by a fraction, while avoiding unnecessary