Browse Source

bitfury: Avoid crashing when broken devices report more jobs flushed than they had to flush

Luke Dashjr 11 years ago
parent
commit
b0d7af52fa
1 changed files with 9 additions and 0 deletions
  1. 9 0
      driver-bitforce.c

+ 9 - 0
driver-bitforce.c

@@ -1965,6 +1965,15 @@ void bitforce_queue_flush(struct thr_info *thr)
 		flushed = 0;
 		flushed = 0;
 	}
 	}
 	
 	
+	if (flushed > data->queued)
+	{
+		applog(LOG_WARNING, "%"PRIpreprv": Flushed %u jobs from device, but only %u were queued",
+		       bitforce->proc_repr, flushed, data->queued);
+		inc_hw_errors_only(thr);
+		// We need to avoid trying to delete more items than we've sent, or a segfault is upcoming...
+		flushed = data->queued;
+	}
+	
 	data->queued -= flushed;
 	data->queued -= flushed;
 	
 	
 	applog(LOG_DEBUG, "%"PRIpreprv": Flushed %u jobs from device and %d from driver (queued<=%d)",
 	applog(LOG_DEBUG, "%"PRIpreprv": Flushed %u jobs from device and %d from driver (queued<=%d)",