]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
sbsa_gwdt: Calculate timeout with 64-bit math
authorDarren Hart <darren@os.amperecomputing.com>
Thu, 21 Sep 2023 09:02:36 +0000 (02:02 -0700)
committerWim Van Sebroeck <wim@linux-watchdog.org>
Sun, 29 Oct 2023 18:45:05 +0000 (19:45 +0100)
Commit abd3ac7902fb ("watchdog: sbsa: Support architecture version 1")
introduced new timer math for watchdog revision 1 with the 48 bit offset
register.

The gwdt->clk and timeout are u32, but the argument being calculated is
u64. Without a cast, the compiler performs u32 operations, truncating
intermediate steps, resulting in incorrect values.

A watchdog revision 1 implementation with a gwdt->clk of 1GHz and a
timeout of 600s writes 3647256576 to the one shot watchdog instead of
300000000000, resulting in the watchdog firing in 3.6s instead of 600s.

Force u64 math by casting the first argument (gwdt->clk) as a u64. Make
the order of operations explicit with parenthesis.

Fixes: abd3ac7902fb ("watchdog: sbsa: Support architecture version 1")
Reported-by: Vanshidhar Konda <vanshikonda@os.amperecomputing.com>
Signed-off-by: Darren Hart <darren@os.amperecomputing.com>
Cc: Wim Van Sebroeck <wim@linux-watchdog.org>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: linux-watchdog@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: <stable@vger.kernel.org> # 5.14.x
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Link: https://lore.kernel.org/r/7d1713c5ffab19b0f3de796d82df19e8b1f340de.1695286124.git.darren@os.amperecomputing.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
drivers/watchdog/sbsa_gwdt.c

index 421ebcda62e645af6808a16bbb2aa4a3a9b8066a..5f23913ce3b49c4d054eaebf9057e99b4689f8d7 100644 (file)
@@ -152,14 +152,14 @@ static int sbsa_gwdt_set_timeout(struct watchdog_device *wdd,
        timeout = clamp_t(unsigned int, timeout, 1, wdd->max_hw_heartbeat_ms / 1000);
 
        if (action)
-               sbsa_gwdt_reg_write(gwdt->clk * timeout, gwdt);
+               sbsa_gwdt_reg_write((u64)gwdt->clk * timeout, gwdt);
        else
                /*
                 * In the single stage mode, The first signal (WS0) is ignored,
                 * the timeout is (WOR * 2), so the WOR should be configured
                 * to half value of timeout.
                 */
-               sbsa_gwdt_reg_write(gwdt->clk / 2 * timeout, gwdt);
+               sbsa_gwdt_reg_write(((u64)gwdt->clk / 2) * timeout, gwdt);
 
        return 0;
 }