[1/4] btrfs: fix the bug that __tree_search() returns the wrong result in extent_map.c
diff mbox

Message ID 4B273290.6090503@cn.fujitsu.com
State New, archived
Headers show

Commit Message

Miao Xie Dec. 15, 2009, 6:54 a.m. UTC
None

Patch
diff mbox

diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c
index 46bea0f..16744f4 100644
--- a/fs/btrfs/extent_map.c
+++ b/fs/btrfs/extent_map.c
@@ -136,20 +136,15 @@  static struct rb_node *__tree_search(struct rb_root *root, u64 offset,
 
 	if (prev_ret) {
 		orig_prev = prev;
-		while (prev && offset >= extent_map_end(prev_entry)) {
-			prev = rb_next(prev);
-			prev_entry = rb_entry(prev, struct extent_map, rb_node);
-		}
+		if (prev && offset < prev_entry->start)
+			prev = rb_prev(prev);
 		*prev_ret = prev;
 		prev = orig_prev;
 	}
 
 	if (next_ret) {
-		prev_entry = rb_entry(prev, struct extent_map, rb_node);
-		while (prev && offset < prev_entry->start) {
-			prev = rb_prev(prev);
-			prev_entry = rb_entry(prev, struct extent_map, rb_node);
-		}
+		if (prev && offset >= extent_map_end(prev_entry))
+			prev = rb_next(prev);
 		*next_ret = prev;
 	}
 	return NULL;