Commit b8484956e6f119a7805a144a6194e3cbd9937ad3

Con Kolivas 2012-07-06T16:44:55

Add sanity checking to make sure we don't make sleep_ms less than 0 in bitforce.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
diff --git a/driver-bitforce.c b/driver-bitforce.c
index 9389026..2974361 100644
--- a/driver-bitforce.c
+++ b/driver-bitforce.c
@@ -376,8 +376,12 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work)
 	        delay_time_ms = bitforce->sleep_ms;
 		if (bitforce->wait_ms > bitforce->sleep_ms + (WORK_CHECK_INTERVAL_MS * 2))
 			bitforce->sleep_ms += (bitforce->wait_ms - bitforce->sleep_ms) / 2;
-		else if (bitforce->wait_ms == bitforce->sleep_ms)
+		else if (bitforce->wait_ms == bitforce->sleep_ms) {
+			if (bitforce->sleep_ms > WORK_CHECK_INTERVAL_MS)
+				bitforce->sleep_ms -= WORK_CHECK_INTERVAL_MS;
+			else if (bitforce->sleep_ms > BITFORCE_CHECK_INTERVAL_MS)
 				bitforce->sleep_ms -= BITFORCE_CHECK_INTERVAL_MS;
+		}
 
 		if (delay_time_ms != bitforce->sleep_ms)
 			  applog(LOG_DEBUG, "BFL%i: Wait time changed to: %d", bitforce->device_id, bitforce->sleep_ms, bitforce->wait_ms);