Btrfs: add NULL check for do_walk_down()
authorMiao Xie <miaox@cn.fujitsu.com>
Thu, 25 Mar 2010 12:37:12 +0000 (12:37 +0000)
committerChris Mason <chris.mason@oracle.com>
Wed, 31 Mar 2010 01:19:08 +0000 (21:19 -0400)
btrfs_find_create_tree_block() may return NULL, so we must check the returned
value, or we will access a NULL pointer.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
fs/btrfs/extent-tree.c

index 1727b26fb1944706f87210ddec2ca07a944b83e0..503a18eaef5273ad39038ca9d10e5bb590b10fd1 100644 (file)
@@ -5205,6 +5205,8 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
        next = btrfs_find_tree_block(root, bytenr, blocksize);
        if (!next) {
                next = btrfs_find_create_tree_block(root, bytenr, blocksize);
+               if (!next)
+                       return -ENOMEM;
                reada = 1;
        }
        btrfs_tree_lock(next);
@@ -5417,7 +5419,8 @@ static noinline int walk_down_tree(struct btrfs_trans_handle *trans,
                if (ret > 0) {
                        path->slots[level]++;
                        continue;
-               }
+               } else if (ret < 0)
+                       return ret;
                level = wc->level;
        }
        return 0;