svn commit: r328844 - stable/11/sys/dev/amdsbwd

Andriy Gapon avg at FreeBSD.org
Sun Feb 4 13:57:16 UTC 2018


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 {


More information about the svn-src-all mailing list