Package: langford / 0.0.20130228-6

circular Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Description: Make ring buffer code overflow free
Author: Simon Richter <sjr@debian.org>
Last-Update: 2013-01-08

Index: langford-0.0.20130228/langford.c
===================================================================
--- langford-0.0.20130228.orig/langford.c
+++ langford-0.0.20130228/langford.c
@@ -55,22 +55,20 @@ static struct task_struct	*dev_write_thr
 /**Figures out elements are used in a circular buffer
 */
 static unsigned int circ_buff_filled(unsigned int start, unsigned int end, unsigned int len) {
-	int		rc;
-
-	rc = end - start;
-
-	if (rc < 0) {
-		rc = len + rc;
-	};
-
-	return rc;
+	if (start > end)
+		return len - start + end;
+	else
+		return end - start;
 };
 
 
 /**Figures out how many elements of a circular buffer are available to be filled
 */
 static unsigned int circ_buff_avail(unsigned int start, unsigned int end, unsigned int len) {
-	return len - circ_buff_filled(start, end, len) - 1;
+	if (start > end)
+		return start - end - 1;
+	else
+		return len - end + start - 1;
 };