Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 4 Feb 2018 13:58:29 +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-10@freebsd.org
Subject:   svn commit: r328845 - stable/10/sys/dev/amdsbwd
Message-ID:  <201802041358.w14DwTAp037296@repo.freebsd.org>

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

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

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

Modified: stable/10/sys/dev/amdsbwd/amdsbwd.c
==============================================================================
--- stable/10/sys/dev/amdsbwd/amdsbwd.c	Sun Feb  4 13:57:15 2018	(r328844)
+++ stable/10/sys/dev/amdsbwd/amdsbwd.c	Sun Feb  4 13:58:29 2018	(r328845)
@@ -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?201802041358.w14DwTAp037296>