[PATCH] math64: prevent double calculation of DIV64_U64_ROUND_UP() arguments
From: Roman Gushchin
Date: Wed Aug 29 2018 - 17:14:48 EST
Cause the DIV64_U64_ROUND_UP(ll, d) macro to cache
the result of (d) expression in a local variable to
avoid double calculation, which might bring unexpected
side effects.
Signed-off-by: Roman Gushchin <guro@xxxxxx>
---
include/linux/math64.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/include/linux/math64.h b/include/linux/math64.h
index 94af3d9c73e7..bb2c84afb80c 100644
--- a/include/linux/math64.h
+++ b/include/linux/math64.h
@@ -281,6 +281,7 @@ static inline u64 mul_u64_u32_div(u64 a, u32 mul, u32 divisor)
}
#endif /* mul_u64_u32_div */
-#define DIV64_U64_ROUND_UP(ll, d) div64_u64((ll) + (d) - 1, (d))
+#define DIV64_U64_ROUND_UP(ll, d) \
+ ({ u64 _tmp = (d); div64_u64((ll) + _tmp - 1, _tmp); })
#endif /* _LINUX_MATH64_H */
--
2.17.1