mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Huibin Hong <huibin.hong@rock-chips.com>
To: linux@roeck-us.net
Cc: huangtao@rock-chips.com, Huibin Hong <huibin.hong@rock-chips.com>,
	Wim Van Sebroeck <wim@iguana.be>,
	linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] watchdog: dw_wdt: fix overflow issue in dw_wdt_top_in_seconds
Date: Tue, 15 Aug 2017 10:45:13 +0800	[thread overview]
Message-ID: <1502765113-1025-1-git-send-email-huibin.hong@rock-chips.com> (raw)

If top is 15, (1 << (16 + top)) may be negative.

Signed-off-by: Huibin Hong <huibin.hong@rock-chips.com>
---

Changes in v2:
    - Rebase mainline Linux 4.13-rc5

 drivers/watchdog/dw_wdt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/watchdog/dw_wdt.c b/drivers/watchdog/dw_wdt.c
index 36be987..59ed958 100644
--- a/drivers/watchdog/dw_wdt.c
+++ b/drivers/watchdog/dw_wdt.c
@@ -72,7 +72,9 @@ static inline int dw_wdt_top_in_seconds(struct dw_wdt *dw_wdt, unsigned top)
 	 * There are 16 possible timeout values in 0..15 where the number of
 	 * cycles is 2 ^ (16 + i) and the watchdog counts down.
 	 */
-	return (1U << (16 + top)) / dw_wdt->rate;
+	unsigned int cycles = 1 << (16 + top);
+
+	return (cycles / clk_get_rate(dw_wdt.clk));
 }
 
 static int dw_wdt_get_top(struct dw_wdt *dw_wdt)
-- 
1.9.1

             reply	other threads:[~2017-08-15  2:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-15  2:45 Huibin Hong [this message]
2017-08-15  4:49 ` Guenter Roeck
2017-08-16 20:24 ` kbuild test robot
2017-08-16 20:30 ` kbuild test robot

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=1502765113-1025-1-git-send-email-huibin.hong@rock-chips.com \
    --to=huibin.hong@rock-chips.com \
    --cc=huangtao@rock-chips.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=wim@iguana.be \
    /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®