From: Stephen Hemminger <sthem...@microsoft.com

This fixes a day one bug in circular ring buffer.  The ring buffer
will get stuck if the number of bytes written exactly fills the
ring buffer size.  The root cause is an off by one bug.

Ring empty state is when read_index == write_loc.
The very last slot in the circular buffer must never be filled
otherwise there is no way to tell the difference between completely
full and empty!

Signed-off-by: Stephen Hemminger <step...@networkplumber.org>
---
Please queue for stable as well

 include/linux/hyperv.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index cd184bd..28f88de 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -150,6 +150,7 @@ hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info 
*rbi,
 
        *write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
                read_loc - write_loc;
+       *write -= 1;
        *read = dsize - *write;
 }
 
@@ -177,7 +178,8 @@ static inline u32 hv_get_bytes_to_write(struct 
hv_ring_buffer_info *rbi)
 
        write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
                read_loc - write_loc;
-       return write;
+       /* make sure ring never gets completely full */
+       return write - 1;
 }
 
 /*
-- 
2.7.4

_______________________________________________
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

Reply via email to