[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250623211116.1395-1-ansuelsmth@gmail.com>
Date: Mon, 23 Jun 2025 23:11:12 +0200
From: Christian Marangi <ansuelsmth@...il.com>
To: Uwe Kleine-König <ukleinek@...nel.org>,
Lukas Wunner <lukas@...ner.de>,
AngeloGioacchino Del Regno <angelogioacchino.delregno@...labora.com>,
Herbert Xu <herbert@...dor.apana.org.au>,
Andy Shevchenko <andy@...nel.org>,
Jonathan Cameron <Jonathan.Cameron@...wei.com>,
Christian Marangi <ansuelsmth@...il.com>,
linux-kernel@...r.kernel.org,
linux-pwm@...r.kernel.org
Subject: [PATCH v15 1/2] math.h: provide rounddown_ull variant for rounddown MACRO
There is currently a problem with the usage of rounddown MACRO with
u64 dividends. This cause compilation error on specific arch where
64bit division is done on 32bit system.
To be more specific GCC try optimize the function and replace it with
__umoddi3 but this is actually not compiled in the kernel.
Example:
pwm-airoha.c:(.text+0x8f8): undefined reference to `__umoddi3'
To better handle this, introduce a variant of rounddown MACRO,
rounddown_ull that can be used exactly for this scenario.
rounddown_ull new MACRO use the do_div MACRO that do the heavy work of
handling internally all the magic for 64bit division on 32bit (and
indirectly fix the compilation error).
Signed-off-by: Christian Marangi <ansuelsmth@...il.com>
---
Changes v15:
- Add this patch
include/linux/math.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/include/linux/math.h b/include/linux/math.h
index 0198c92cbe3e..1cda6578e0aa 100644
--- a/include/linux/math.h
+++ b/include/linux/math.h
@@ -88,6 +88,17 @@
__x - (__x % (y)); \
} \
)
+/*
+ * Same as above but for u64 dividends. divisor must be a 32-bit
+ * number.
+ */
+#define rounddown_ull(x, y) ( \
+{ \
+ unsigned long long __x = (x); \
+ unsigned long long _tmp = __x; \
+ __x - do_div(_tmp, (y)); \
+} \
+)
/*
* Divide positive or negative dividend by positive or negative divisor
--
2.48.1
Powered by blists - more mailing lists