Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 4 Feb 2018 13:57:15 +0000 (UTC)
From:      Andriy Gapon <avg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r328844 - stable/11/sys/dev/amdsbwd
Message-ID:  <201802041357.w14DvFWf037185@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avg
Date: Sun Feb  4 13:57:15 2018
New Revision: 328844
URL: https://svnweb.freebsd.org/changeset/base/328844

Log:
  MFC r327775: amdsbwd: fix handling of timeout values beyond the supported range

Modified:
  stable/11/sys/dev/amdsbwd/amdsbwd.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/amdsbwd/amdsbwd.c
==============================================================================
--- stable/11/sys/dev/amdsbwd/amdsbwd.c	Sun Feb  4 13:55:20 2018	(r328843)
+++ stable/11/sys/dev/amdsbwd/amdsbwd.c	Sun Feb  4 13:57:15 2018	(r328844)
@@ -208,21 +208,30 @@ static void
 amdsbwd_event(void *arg, unsigned int cmd, int *error)
 {
 	struct amdsbwd_softc *sc = arg;
-	unsigned int timeout;
+	uint64_t 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;
+	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 {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802041357.w14DvFWf037185>