From: Yinghai Lu <yinghai@kernel.org>
To: "H. Peter Anvin" <hpa@zytor.com>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@elte.hu>,
Joshua Covington <joshuacov@googlemail.com>,
linux-kernel@vger.kernel.org, Yinghai Lu <yinghai@kernel.org>,
<stable@vger.kernel.org>
Subject: [PATCH 2/2] x86, range: make add_range use blank slot
Date: Sun, 9 Jun 2013 13:00:05 -0700 [thread overview]
Message-ID: <1370808005-23565-2-git-send-email-yinghai@kernel.org> (raw)
In-Reply-To: <1370808005-23565-1-git-send-email-yinghai@kernel.org>
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;
}
prev parent reply other threads:[~2013-06-09 20:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-09 20:00 [PATCH 1/2] x86,mtrr: Fix original mtrr range get for mtrr_cleanup Yinghai Lu
2013-06-09 20:00 ` Yinghai Lu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1370808005-23565-2-git-send-email-yinghai@kernel.org \
--to=yinghai@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=hpa@zytor.com \
--cc=joshuacov@googlemail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox