diff mbox series

[v2] watchdog: sp805: Report correct timeleft at maximum

Message ID 20241203095744.3001795-1-mac@mcrowe.com
State New
Headers show
Series [v2] watchdog: sp805: Report correct timeleft at maximum | expand

Commit Message

Mike Crowe Dec. 3, 2024, 9:57 a.m. UTC
sp805_wdt::load_val is of type unsigned int. When the interrupt is
inactive wdt_timeleft adds one to the value, and then adds that to the
value used to calculate the time remaining. Unfortunately it's not
unlikely that load_val contains LOAD_MAX, which is 0xFFFFFFFF and wraps
to zero when one is added to it, resulting in the time left being
understated by about 21.7s. Fix this by ensuring the addition happens as
64-bit.

Signed-off-by: Mike Crowe <mac@mcrowe.com>
---
 drivers/watchdog/sp805_wdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Guenter Roeck Dec. 3, 2024, 3:16 p.m. UTC | #1
On 12/3/24 01:57, Mike Crowe wrote:
> sp805_wdt::load_val is of type unsigned int. When the interrupt is
> inactive wdt_timeleft adds one to the value, and then adds that to the
> value used to calculate the time remaining. Unfortunately it's not
> unlikely that load_val contains LOAD_MAX, which is 0xFFFFFFFF and wraps
> to zero when one is added to it, resulting in the time left being
> understated by about 21.7s. Fix this by ensuring the addition happens as
> 64-bit.
> 
> Signed-off-by: Mike Crowe <mac@mcrowe.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

Please provide change logs in future patches.

Guenter

> ---
>   drivers/watchdog/sp805_wdt.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/watchdog/sp805_wdt.c b/drivers/watchdog/sp805_wdt.c
> index 109e2e37e8f0..4400c439c718 100644
> --- a/drivers/watchdog/sp805_wdt.c
> +++ b/drivers/watchdog/sp805_wdt.c
> @@ -128,7 +128,7 @@ static unsigned int wdt_timeleft(struct watchdog_device *wdd)
>   
>   	/*If the interrupt is inactive then time left is WDTValue + WDTLoad. */
>   	if (!(readl_relaxed(wdt->base + WDTRIS) & INT_MASK))
> -		load += wdt->load_val + 1;
> +		load += (u64)wdt->load_val + 1;
>   	spin_unlock(&wdt->lock);
>   
>   	return div_u64(load, wdt->rate);
diff mbox series

Patch

diff --git a/drivers/watchdog/sp805_wdt.c b/drivers/watchdog/sp805_wdt.c
index 109e2e37e8f0..4400c439c718 100644
--- a/drivers/watchdog/sp805_wdt.c
+++ b/drivers/watchdog/sp805_wdt.c
@@ -128,7 +128,7 @@  static unsigned int wdt_timeleft(struct watchdog_device *wdd)
 
 	/*If the interrupt is inactive then time left is WDTValue + WDTLoad. */
 	if (!(readl_relaxed(wdt->base + WDTRIS) & INT_MASK))
-		load += wdt->load_val + 1;
+		load += (u64)wdt->load_val + 1;
 	spin_unlock(&wdt->lock);
 
 	return div_u64(load, wdt->rate);