From: Christian Marangi <ansuelsmth@gmail.com>
To: "Uwe Kleine-König" <ukleinek@kernel.org>,
"Lukas Wunner" <lukas@wunner.de>,
"AngeloGioacchino Del Regno"
<angelogioacchino.delregno@collabora.com>,
"Herbert Xu" <herbert@gondor.apana.org.au>,
"Andy Shevchenko" <andy@kernel.org>,
"Jonathan Cameron" <Jonathan.Cameron@huawei.com>,
"Christian Marangi" <ansuelsmth@gmail.com>,
linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org
Subject: [PATCH v15 1/2] math.h: provide rounddown_ull variant for rounddown MACRO
Date: Mon, 23 Jun 2025 23:11:12 +0200 [thread overview]
Message-ID: <20250623211116.1395-1-ansuelsmth@gmail.com> (raw)
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@gmail.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
next reply other threads:[~2025-06-23 21:11 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-23 21:11 Christian Marangi [this message]
2025-06-23 21:11 ` [PATCH v15 2/2] pwm: airoha: Add support for EN7581 SoC Christian Marangi
2025-06-24 6:37 ` Andy Shevchenko
2025-06-24 8:41 ` Christian Marangi
2025-06-24 13:05 ` Andy Shevchenko
2025-06-24 6:08 ` [PATCH v15 1/2] math.h: provide rounddown_ull variant for rounddown MACRO Andy Shevchenko
2025-06-24 7:45 ` Christian Marangi
2025-06-24 8:40 ` Andy Shevchenko
2025-06-24 8:44 ` Andy Shevchenko
2025-06-24 8:48 ` Christian Marangi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250623211116.1395-1-ansuelsmth@gmail.com \
--to=ansuelsmth@gmail.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=andy@kernel.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=ukleinek@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.