summaryrefslogtreecommitdiffstats
path: root/x86-range-make-add_range-use-blank-slot.patch
blob: 50d3937946486db6459535c5638680195d2764de (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
Now add_range_with_merge will generate blank slot as subtract_range.
we could reach the array limit because of blank slots.

We can let add_range to have second try to use blank slot.

Also use WARN_ONCE to print trace.

Reported-by: Joshua Covington <joshuacov@googlemail.com>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: <stable@vger.kernel.org> v3.9
---
 kernel/range.c |   34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

Index: linux-2.6/kernel/range.c
===================================================================
--- linux-2.6.orig/kernel/range.c
+++ linux-2.6/kernel/range.c
@@ -3,23 +3,34 @@
  */
 #include <linux/kernel.h>
 #include <linux/init.h>
+#include <linux/bug.h>
 #include <linux/sort.h>
-
 #include <linux/range.h>
 
 int add_range(struct range *range, int az, int nr_range, u64 start, u64 end)
 {
-	if (start >= end)
-		return nr_range;
+	int i;
 
-	/* Out of slots: */
-	if (nr_range >= az)
+	if (start >= end)
 		return nr_range;
 
-	range[nr_range].start = start;
-	range[nr_range].end = end;
+	/* Out of slots ? */
+	if (nr_range < az) {
+		i = nr_range;
+		nr_range++;
+	} else {
+		/* find blank slot */
+		for (i = 0; i < az; i++)
+			if (!range[i].end)
+				break;
+		if (i == az) {
+			WARN_ONCE(1, "run out of slot in ranges\n");
+			return az;
+		}
+	}
 
-	nr_range++;
+	range[i].start = start;
+	range[i].end = end;
 
 	return nr_range;
 }
@@ -98,10 +109,9 @@ void subtract_range(struct range *range,
 			if (i < az) {
 				range[i].end = range[j].end;
 				range[i].start = end;
-			} else {
-				pr_err("%s: run out of slot in ranges\n",
-					__func__);
-			}
+			} else
+				WARN_ONCE(1, "run out of slot in ranges\n");
+
 			range[j].end = start;
 			continue;
 		}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/