mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: David Howells <dhowells@redhat.com>,
	Koichi Yasutake <yasutake.koichi@jp.panasonic.com>
Cc: linux-am33-list@redhat.com, linux-kernel@vger.kernel.org,
	Geert Uytterhoeven <geert@linux-m68k.org>
Subject: [PATCH] mn10300: Truncate base in do_div()
Date: Thu, 22 Aug 2013 13:08:47 +0200	[thread overview]
Message-ID: <1377169727-17743-1-git-send-email-geert@linux-m68k.org> (raw)

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


                 reply	other threads:[~2013-08-22 11:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1377169727-17743-1-git-send-email-geert@linux-m68k.org \
    --to=geert@linux-m68k.org \
    --cc=dhowells@redhat.com \
    --cc=linux-am33-list@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yasutake.koichi@jp.panasonic.com \
    /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 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®