diff mbox series

[4/9] linux/kernel.h: import DIV_ROUND_CLOSEST_ULL from Linux

Message ID 1545217401-27018-5-git-send-email-yamada.masahiro@socionext.com
State Accepted
Commit b32aa9ebc57b8db5052e3b97dc5a3349cd91636b
Headers show
Series ARM: dts: uniphier: updates for v2019.01 | expand

Commit Message

Masahiro Yamada Dec. 19, 2018, 11:03 a.m. UTC
Copied from Linux v4.20-rc7.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

 include/linux/kernel.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index bd88483..a85c15d 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