diff mbox series

[V2] MIPS: Fix longstanding errors in div64.h

Message ID 20210407062916.3465459-1-chenhuacai@loongson.cn
State New
Headers show
Series [V2] MIPS: Fix longstanding errors in div64.h | expand

Commit Message

Huacai Chen April 7, 2021, 6:29 a.m. UTC
There are three errors in div64.h caused by commit c21004cd5b4cb7d479514
("MIPS: Rewrite <asm/div64.h> to work with gcc 4.4.0."):

1, Only 32bit kernel need __div64_32(), but the above commit makes it
depend on 64bit kernel by mistake.

2, asm-generic/div64.h should be included after __div64_32() definition.

3, __n should be initialized as *n before use (and "*__n >> 32" should
be "__n >> 32") in __div64_32() definition.

Fixes: c21004cd5b4cb7d479514 ("MIPS: Rewrite <asm/div64.h> to work with gcc 4.4.0.")
Cc: stable@vger.kernel.org
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
---
 arch/mips/include/asm/div64.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

H. Nikolaus Schaller April 7, 2021, 6:53 a.m. UTC | #1
> Am 07.04.2021 um 08:29 schrieb Huacai Chen <chenhuacai@kernel.org>:
> 
> There are three errors in div64.h caused by commit c21004cd5b4cb7d479514
> ("MIPS: Rewrite <asm/div64.h> to work with gcc 4.4.0."):
> 
> 1, Only 32bit kernel need __div64_32(), but the above commit makes it
> depend on 64bit kernel by mistake.
> 
> 2, asm-generic/div64.h should be included after __div64_32() definition.
> 
> 3, __n should be initialized as *n before use (and "*__n >> 32" should
> be "__n >> 32") in __div64_32() definition.
> 
> Fixes: c21004cd5b4cb7d479514 ("MIPS: Rewrite <asm/div64.h> to work with gcc 4.4.0.")
> Cc: stable@vger.kernel.org
> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> ---
> arch/mips/include/asm/div64.h | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/mips/include/asm/div64.h b/arch/mips/include/asm/div64.h
> index dc5ea5736440..3be2318f8e0e 100644
> --- a/arch/mips/include/asm/div64.h
> +++ b/arch/mips/include/asm/div64.h
> @@ -9,9 +9,7 @@
> #ifndef __ASM_DIV64_H
> #define __ASM_DIV64_H
> 
> -#include <asm-generic/div64.h>
> -
> -#if BITS_PER_LONG == 64
> +#if BITS_PER_LONG == 32
> 
> #include <linux/types.h>
> 
> @@ -24,9 +22,9 @@
> 	unsigned long __cf, __tmp, __tmp2, __i;				\
> 	unsigned long __quot32, __mod32;				\
> 	unsigned long __high, __low;					\
> -	unsigned long long __n;						\
> +	unsigned long long __n = *n;					\
> 									\
> -	__high = *__n >> 32;						\
> +	__high = __n >> 32;						\
> 	__low = __n;							\
> 	__asm__(							\
> 	"	.set	push					\n"	\
> @@ -65,4 +63,6 @@
> 
> #endif /* BITS_PER_LONG == 64 */

IMHO these #if/else/endif comments should also be fixed.

> 
> +#include <asm-generic/div64.h>
> +
> #endif /* __ASM_DIV64_H */
> -- 
> 2.27.0
> 

compiles fine now. But I still get a linker issue:

fs/ubifs/budget.o: In function `div_u64_rem':
fs/ubifs/budget.c:(.text+0x1fc): undefined reference to `__div64_32'
fs/ubifs/lpt.o: In function `div_u64_rem':
fs/ubifs/lpt.c:(.text+0x8fc): undefined reference to `__div64_32'
make[2]: *** [vmlinux] Error 1
make[1]: *** [__build_one_by_one] Error 2
make: *** [__sub-make] Error 2

BR and thanks,
Nikolaus Schaller
diff mbox series

Patch

diff --git a/arch/mips/include/asm/div64.h b/arch/mips/include/asm/div64.h
index dc5ea5736440..3be2318f8e0e 100644
--- a/arch/mips/include/asm/div64.h
+++ b/arch/mips/include/asm/div64.h
@@ -9,9 +9,7 @@ 
 #ifndef __ASM_DIV64_H
 #define __ASM_DIV64_H
 
-#include <asm-generic/div64.h>
-
-#if BITS_PER_LONG == 64
+#if BITS_PER_LONG == 32
 
 #include <linux/types.h>
 
@@ -24,9 +22,9 @@ 
 	unsigned long __cf, __tmp, __tmp2, __i;				\
 	unsigned long __quot32, __mod32;				\
 	unsigned long __high, __low;					\
-	unsigned long long __n;						\
+	unsigned long long __n = *n;					\
 									\
-	__high = *__n >> 32;						\
+	__high = __n >> 32;						\
 	__low = __n;							\
 	__asm__(							\
 	"	.set	push					\n"	\
@@ -65,4 +63,6 @@ 
 
 #endif /* BITS_PER_LONG == 64 */
 
+#include <asm-generic/div64.h>
+
 #endif /* __ASM_DIV64_H */