From: Michel Lespinasse <walken@google.com>
To: Sasha Levin <sasha.levin@oracle.com>
Cc: Pekka Enberg <penberg@kernel.org>,
Asias He <asias.hejun@gmail.com>, Ingo Molnar <mingo@elte.hu>,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/3] kvm: ensure non-overlapping intervals in rb_int_insert()
Date: Sat, 24 Nov 2012 18:44:22 -0800 [thread overview]
Message-ID: <1353811464-6462-1-git-send-email-walken@google.com> (raw)
In-Reply-To: <CANN689EzEDuYFdcM3=ir=UZgOhiNeKNpc_ydP8vH00f0nM6PXw@mail.gmail.com>
The rbtree interval API is designed for handling non-overlapping intervals;
modify rb_int_insert() to guarantee this property is maintained by
returning -EEXIST when attempting to insert a new interval that overlaps
an existing interval.
Also fix an issue where the computation of 'result' could trigger an
integer overflow which would break the rbtree ordering.
Signed-off-by: Michel Lespinasse <walken@google.com>
---
tools/kvm/util/rbtree-interval.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/kvm/util/rbtree-interval.c b/tools/kvm/util/rbtree-interval.c
index d7fa96a06a92..fd69252bea02 100644
--- a/tools/kvm/util/rbtree-interval.c
+++ b/tools/kvm/util/rbtree-interval.c
@@ -99,13 +99,13 @@ int rb_int_insert(struct rb_root *root, struct rb_int_node *i_node)
struct rb_node **node = &root->rb_node, *parent = NULL;
while (*node) {
- int result = i_node->low - rb_int(*node)->low;
+ struct rb_int_node *cur = rb_int(*node);
parent = *node;
- if (result < 0)
- node = &((*node)->rb_left);
- else if (result > 0)
- node = &((*node)->rb_right);
+ if (i_node->high <= cur->low)
+ node = &cur->node.rb_left;
+ else if (cur->high <= i_node->low)
+ node = &cur->node.rb_right;
else
return -EEXIST;
}
--
1.7.7.3
next prev parent reply other threads:[~2012-11-25 2:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-25 2:40 [PATCH 0/3] remove kvm's use of augmented rbtree Michel Lespinasse
2012-11-25 2:44 ` Michel Lespinasse [this message]
2012-11-25 2:44 ` [PATCH 2/3] kvm: rb_int_search_single simplification Michel Lespinasse
2012-11-25 2:44 ` [PATCH 3/3] kvm: remove max_high field in rb_int_node structure Michel Lespinasse
2012-11-25 22:14 ` [PATCH 0/3] remove kvm's use of augmented rbtree Sasha Levin
2012-12-10 16:22 ` Sasha Levin
2012-12-10 21:50 ` Michel Lespinasse
2012-12-10 21:57 ` Sasha Levin
2012-12-11 10:30 ` Pekka Enberg
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=1353811464-6462-1-git-send-email-walken@google.com \
--to=walken@google.com \
--cc=asias.hejun@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=penberg@kernel.org \
--cc=sasha.levin@oracle.com \
/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
Powered by JetHome