linux-mips
[Top] [All Lists]

Re: [PATCH v2 5/7] drivers: watchdog: sb_wdog: Fix 32bit linking problem

To: Yousong Zhou <yszhou4tech@gmail.com>
Subject: Re: [PATCH v2 5/7] drivers: watchdog: sb_wdog: Fix 32bit linking problems
From: Ralf Baechle <ralf@linux-mips.org>
Date: Wed, 19 Jun 2013 10:55:09 +0200
Cc: Markos Chandras <markos.chandras@imgtec.com>, linux-mips@linux-mips.org, sibyte-users@bitmover.com, Wim Van Sebroeck <wim@iguana.be>
In-reply-to: <CAECwjAhzJUO4GFmnu3jX8e-UEj2wiVrB8xA3Hu_0iSaf1L1v5w@mail.gmail.com>
List-archive: <http://www.linux-mips.org/archives/linux-mips/>
List-help: <mailto:ecartis@linux-mips.org?Subject=help>
List-id: linux-mips <linux-mips.eddie.linux-mips.org>
List-owner: <mailto:ralf@linux-mips.org>
List-post: <mailto:linux-mips@linux-mips.org>
List-software: Ecartis version 1.0.0
List-subscribe: <mailto:ecartis@linux-mips.org?subject=subscribe%20linux-mips>
List-unsubscribe: <mailto:ecartis@linux-mips.org?subject=unsubscribe%20linux-mips>
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <1371564006-31805-1-git-send-email-markos.chandras@imgtec.com> <20130618141420.GA15141@linux-mips.org> <CAECwjAhzJUO4GFmnu3jX8e-UEj2wiVrB8xA3Hu_0iSaf1L1v5w@mail.gmail.com>
Sender: linux-mips-bounce@linux-mips.org
User-agent: Mutt/1.5.21 (2010-09-15)
On Wed, Jun 19, 2013 at 03:45:07PM +0800, Yousong Zhou wrote:

> I am not quite sure on this. I just digged this[1] out and thought that Linus
>  may not be happy about the operation `tmp_user_dog/1000000`.
> 
> Correct me if I am wrong, please.
> 
> [1] http://lwn.net/Articles/456241/

Well, Linus' posting is about a division by a power of two.  Doing that
by do_div() is not terribly smart.  Now, reading some manuals it turned
out that the register (like most registers on Sibyte SOCs) is 64 bit
but only the lower 23 bits are being used; bits 23..64 always read as
zero.

So the best fix is to truncate the value down to 32 bit then use the plain
old `/' division.

  Ralf

Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

 drivers/watchdog/sb_wdog.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/watchdog/sb_wdog.c b/drivers/watchdog/sb_wdog.c
index 25c7a3f..ea5d84a 100644
--- a/drivers/watchdog/sb_wdog.c
+++ b/drivers/watchdog/sb_wdog.c
@@ -208,7 +208,7 @@ static long sbwdog_ioctl(struct file *file, unsigned int 
cmd,
                 * get the remaining count from the ... count register
                 * which is 1*8 before the config register
                 */
-               ret = put_user(__raw_readq(user_dog - 8) / 1000000, p);
+               ret = put_user((u32)__raw_readq(user_dog - 8) / 1000000, p);
                break;
        }
        return ret;

<Prev in Thread] Current Thread [Next in Thread>