[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230518154648.581643-4-adobriyan@gmail.com>
Date: Thu, 18 May 2023 18:46:45 +0300
From: Alexey Dobriyan <adobriyan@...il.com>
To: akpm@...ux-foundation.org
Cc: linux-kernel@...r.kernel.org, adobriyan@...il.com
Subject: [PATCH 4/8] auto: promote DIV64_U64_ROUND_UP macro to function
so that people don't convert it to "auto".
Second argument is cast to u64:
u64 _tmp = (d);
so it's safe to make it function argument of type u64.
First argument is used like this:
(ll) + _tmp - 1
which is
typeof(ll) + u64 - int
If u64 is "unsigned long long" then everything will be promoted to it,
so making promotion earlier in function argument is OK.
If u64 is "unsigned long" and typeof(ll) is ranked lower than
"unsigned long" then it will be promoted to "unsigned long",
then it is OK to promote to u64 earlier as function argument.
If u64 is "unsigned long" and typeof(ll) is "long long" or
"unsigned long long" then expression will be promoted to typeof(ll)
but then everything will be truncated to "u64" when passed to
div64_u64(). Thus having type wider that "u64" doesn't really matter.
Signed-off-by: Alexey Dobriyan <adobriyan@...il.com>
---
include/linux/math64.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/include/linux/math64.h b/include/linux/math64.h
index 8b9191a2849e..7e0e2625dc35 100644
--- a/include/linux/math64.h
+++ b/include/linux/math64.h
@@ -298,8 +298,10 @@ u64 mul_u64_u64_div_u64(u64 a, u64 mul, u64 div);
*
* Return: dividend / divisor rounded up
*/
-#define DIV64_U64_ROUND_UP(ll, d) \
- ({ u64 _tmp = (d); div64_u64((ll) + _tmp - 1, _tmp); })
+static inline u64 DIV64_U64_ROUND_UP(u64 ll, u64 d)
+{
+ return div64_u64(ll + d - 1, d);
+}
/**
* DIV64_U64_ROUND_CLOSEST - unsigned 64bit divide with 64bit divisor rounded to nearest integer
--
2.40.1
Powered by blists - more mailing lists