kernel/x86-range-make-add_range-us...

80 lines
2.0 KiB
Diff

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/