| 1 |
Description: Make ring buffer code overflow free |
| 2 |
Author: Simon Richter <[email protected]> |
| 3 |
Last-Update: 2013-01-08 |
| 4 |
|
| 5 |
Index: langford-0.0.20130228/langford.c |
| 6 |
=================================================================== |
| 7 |
--- langford-0.0.20130228.orig/langford.c |
| 8 |
+++ langford-0.0.20130228/langford.c |
| 9 |
@@ -55,22 +55,20 @@ static struct task_struct *dev_write_thr |
| 10 |
/**Figures out elements are used in a circular buffer |
| 11 |
*/ |
| 12 |
static unsigned int circ_buff_filled(unsigned int start, unsigned int end, unsigned int len) { |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
+ if (start > end) |
| 23 |
+ return len - start + end; |
| 24 |
+ else |
| 25 |
+ return end - start; |
| 26 |
}; |
| 27 |
|
| 28 |
|
| 29 |
/**Figures out how many elements of a circular buffer are available to be filled |
| 30 |
*/ |
| 31 |
static unsigned int circ_buff_avail(unsigned int start, unsigned int end, unsigned int len) { |
| 32 |
|
| 33 |
+ if (start > end) |
| 34 |
+ return start - end - 1; |
| 35 |
+ else |
| 36 |
+ return len - end + start - 1; |
| 37 |
}; |
| 38 |
|
| 39 |
|