diff options
author | avg <avg@FreeBSD.org> | 2018-02-04 13:57:15 +0000 |
---|---|---|
committer | avg <avg@FreeBSD.org> | 2018-02-04 13:57:15 +0000 |
commit | eeee39edcc0d51e76cbf53aa59fc23b16ebffa5b (patch) | |
tree | 88125bec5a7c1c73a1e6427b0697af449708f476 | |
parent | 98ed3092864a484e3ad9044f4fb42f83745bc0d0 (diff) | |
download | FreeBSD-src-eeee39edcc0d51e76cbf53aa59fc23b16ebffa5b.zip FreeBSD-src-eeee39edcc0d51e76cbf53aa59fc23b16ebffa5b.tar.gz |
MFC r327775: amdsbwd: fix handling of timeout values beyond the supported range
-rw-r--r-- | sys/dev/amdsbwd/amdsbwd.c | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/sys/dev/amdsbwd/amdsbwd.c b/sys/dev/amdsbwd/amdsbwd.c index 628aef2..fa38c91 100644 --- a/sys/dev/amdsbwd/amdsbwd.c +++ b/sys/dev/amdsbwd/amdsbwd.c @@ -208,21 +208,30 @@ static void amdsbwd_event(void *arg, unsigned int cmd, int *error) { struct amdsbwd_softc *sc = arg; - unsigned int timeout; - - /* convert from power-of-two-ns to WDT ticks */ - cmd &= WD_INTERVAL; - if (cmd < WD_TO_1SEC) - cmd = 0; - if (cmd) { - timeout = ((uint64_t)1 << (cmd - WD_TO_1MS)) / sc->ms_per_tick; + uint64_t timeout; + + if (cmd != 0) { + timeout = 0; + cmd &= WD_INTERVAL; + if (cmd >= WD_TO_1MS) { + timeout = (uint64_t)1 << (cmd - WD_TO_1MS); + timeout = timeout / sc->ms_per_tick; + } + /* For a too short timeout use 1 tick. */ + if (timeout == 0) + timeout = 1; + /* For a too long timeout stop the timer. */ if (timeout > sc->max_ticks) - timeout = sc->max_ticks; - if (timeout != sc->timeout) { + timeout = 0; + } else { + timeout = 0; + } + + if (timeout != 0) { + if (timeout != sc->timeout) amdsbwd_tmr_set(sc, timeout); - if (!sc->active) - amdsbwd_tmr_enable(sc); - } + if (!sc->active) + amdsbwd_tmr_enable(sc); amdsbwd_tmr_reload(sc); *error = 0; } else { |