From c7f02e5e2141c0dbf07bc82fd40ee7d6cad95229 Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jeremy@system76.com>
Date: Wed, 11 Sep 2019 21:03:07 -0600
Subject: [PATCH] rtl8168d: fix calculation of next read size

---
 rtl8168d/src/device.rs | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/rtl8168d/src/device.rs b/rtl8168d/src/device.rs
index 502d66ec..a1b19c44 100644
--- a/rtl8168d/src/device.rs
+++ b/rtl8168d/src/device.rs
@@ -264,12 +264,17 @@ impl Rtl8168 {
     }
 
     pub fn next_read(&self) -> usize {
-        for rd in self.receive_ring.iter() {
-            if ! rd.ctrl.readf(OWN) {
-                return rd.ctrl.read() as usize & 0x3FFF;
-            }
+        let mut receive_i = self.receive_i;
+        if receive_i >= self.receive_ring.len() {
+            receive_i = 0;
+        }
+
+        let rd = &self.receive_ring[receive_i];
+        if ! rd.ctrl.readf(OWN) {
+            (rd.ctrl.read() & 0x3FFF) as usize
+        } else {
+            0
         }
-        0
     }
 
     pub unsafe fn init(&mut self) {
-- 
GitLab