mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] mn10300: Truncate base in do_div()
@ 2013-08-22 11:08 Geert Uytterhoeven
  0 siblings, 0 replies; only message in thread
From: Geert Uytterhoeven @ 2013-08-22 11:08 UTC (permalink / raw)
  To: David Howells, Koichi Yasutake
  Cc: linux-am33-list, linux-kernel, Geert Uytterhoeven

Explicitly truncate the second operand of do_div() to 32 bits to guard
against bogus code calling it with a 64-bit divisor.

Based on commit ea077b1b96e073eac5c3c5590529e964767fc5f7 ("m68k: Truncate
base in do_div()")

While it doesn't really hurt on little-endian mn10300, unlike on m68k,
mn10300 was the only remaining architecture not doing this.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
Compile-tested only.

 arch/mn10300/include/asm/div64.h |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/arch/mn10300/include/asm/div64.h b/arch/mn10300/include/asm/div64.h
index 503efab..ff69f34 100644
--- a/arch/mn10300/include/asm/div64.h
+++ b/arch/mn10300/include/asm/div64.h
@@ -36,12 +36,13 @@ extern void ____unhandled_size_in_do_div___(void);
 #define do_div(n, base)							\
 ({									\
 	unsigned __rem = 0;						\
+	unsigned __base = (base);					\
 	if (sizeof(n) <= 4) {						\
 		asm("mov	%1,mdr	\n"				\
 		    "divu	%2,%0	\n"				\
 		    "mov	mdr,%1	\n"				\
 		    : "+r"(n), "=d"(__rem)				\
-		    : "r"(base), "1"(__rem)				\
+		    : "r"(__base), "1"(__rem)				\
 		    : CLOBBER_MDR_CC					\
 		    );							\
 	} else if (sizeof(n) <= 8) {					\
@@ -52,14 +53,14 @@ extern void ____unhandled_size_in_do_div___(void);
 		__quot.l = n;						\
 		asm("mov	%0,mdr	\n"	/* MDR = 0 */		\
 		    "divu	%3,%1	\n"				\
-		    /* __quot.MSL = __div.MSL / base, */		\
-		    /* MDR = MDR:__div.MSL % base */			\
+		    /* __quot.MSL = __div.MSL / __base, */		\
+		    /* MDR = MDR:__div.MSL % __base */			\
 		    "divu	%3,%2	\n"				\
-		    /* __quot.LSL = MDR:__div.LSL / base, */		\
-		    /* MDR = MDR:__div.LSL % base */			\
+		    /* __quot.LSL = MDR:__div.LSL / __base, */		\
+		    /* MDR = MDR:__div.LSL % __base */			\
 		    "mov	mdr,%0	\n"				\
 		    : "=d"(__rem), "=r"(__quot.w[1]), "=r"(__quot.w[0])	\
-		    : "r"(base), "0"(__rem), "1"(__quot.w[1]),		\
+		    : "r"(__base), "0"(__rem), "1"(__quot.w[1]),	\
 		      "2"(__quot.w[0])					\
 		    : CLOBBER_MDR_CC					\
 		    );							\
-- 
1.7.9.5


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-08-22 11:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-22 11:08 [PATCH] mn10300: Truncate base in do_div() Geert Uytterhoeven

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®