[tip: x86/urgent] x86/div64: Fix addition of large constants in mul_u64_add_u64_div_u64()
From: tip-bot2 for David Laight
Date: Thu Sep 10 2026 - 14:00:30 EST
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: f65d38155aef069c897a64643a03db237dd1e0c8
Gitweb: https://git.kernel.org/tip/f65d38155aef069c897a64643a03db237dd1e0c8
Author: David Laight <david.laight.linux@xxxxxxxxx>
AuthorDate: Mon, 03 Aug 2026 10:47:01 +01:00
Committer: Borislav Petkov (AMD) <bp@xxxxxxxxx>
CommitterDate: Thu, 10 Sep 2026 10:40:22 -07:00
x86/div64: Fix addition of large constants in mul_u64_add_u64_div_u64()
Adding constants over 2^31 fails to compile because the ADD instruction only
supports 32bit signed immediates.
Replace the "irm" constraint with "erm" so that the compiler loads large
constants into a register.
Found by a patch to drivers/iio/frequency/ad9910.c
[ bp: Massage commit message. ]
Fixes: 6480241f31f5 ("lib: add mul_u64_add_u64_div_u64() and mul_u64_u64_div_u64_roundup()")
Signed-off-by: David Laight <david.laight.linux@xxxxxxxxx>
Signed-off-by: Borislav Petkov (AMD) <bp@xxxxxxxxx>
Reviewed-by: H. Peter Anvin <hpa@xxxxxxxxx>
Link: https://patch.msgid.link/20260803094702.3852-2-david.laight.linux@xxxxxxxxx
---
arch/x86/include/asm/div64.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
index 30fd06e..8a2d343 100644
--- a/arch/x86/include/asm/div64.h
+++ b/arch/x86/include/asm/div64.h
@@ -111,7 +111,7 @@ static inline u64 mul_u64_add_u64_div_u64(u64 rax, u64 mul, u64 add, u64 div)
if (!statically_true(!add))
asm ("addq %[add], %[lo]; adcq $0, %[hi]" :
- [lo] "+r" (rax), [hi] "+r" (rdx) : [add] "irm" (add));
+ [lo] "+r" (rax), [hi] "+r" (rdx) : [add] "erm" (add));
asm ("divq %[div]" : "+a" (rax), "+d" (rdx) : [div] "rm" (div));