浏览代码

btrfs: check NULL or not

Should check if functions returns NULL or not.

Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Tsutomu Itoh 14 年之前
父节点
当前提交
91ca338d77
共有 3 个文件被更改,包括 16 次插入0 次删除
  1. 6 0
      fs/btrfs/ctree.c
  2. 8 0
      fs/btrfs/disk-io.c
  3. 2 0
      fs/btrfs/extent_io.c

+ 6 - 0
fs/btrfs/ctree.c

@@ -2516,6 +2516,9 @@ static int push_leaf_right(struct btrfs_trans_handle *trans, struct btrfs_root
 	btrfs_assert_tree_locked(path->nodes[1]);
 	btrfs_assert_tree_locked(path->nodes[1]);
 
 
 	right = read_node_slot(root, upper, slot + 1);
 	right = read_node_slot(root, upper, slot + 1);
+	if (right == NULL)
+		return 1;
+
 	btrfs_tree_lock(right);
 	btrfs_tree_lock(right);
 	btrfs_set_lock_blocking(right);
 	btrfs_set_lock_blocking(right);
 
 
@@ -2766,6 +2769,9 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_root
 	btrfs_assert_tree_locked(path->nodes[1]);
 	btrfs_assert_tree_locked(path->nodes[1]);
 
 
 	left = read_node_slot(root, path->nodes[1], slot - 1);
 	left = read_node_slot(root, path->nodes[1], slot - 1);
+	if (left == NULL)
+		return 1;
+
 	btrfs_tree_lock(left);
 	btrfs_tree_lock(left);
 	btrfs_set_lock_blocking(left);
 	btrfs_set_lock_blocking(left);
 
 

+ 8 - 0
fs/btrfs/disk-io.c

@@ -353,6 +353,10 @@ static int csum_dirty_buffer(struct btrfs_root *root, struct page *page)
 	WARN_ON(len == 0);
 	WARN_ON(len == 0);
 
 
 	eb = alloc_extent_buffer(tree, start, len, page, GFP_NOFS);
 	eb = alloc_extent_buffer(tree, start, len, page, GFP_NOFS);
+	if (eb == NULL) {
+		WARN_ON(1);
+		goto out;
+	}
 	ret = btree_read_extent_buffer_pages(root, eb, start + PAGE_CACHE_SIZE,
 	ret = btree_read_extent_buffer_pages(root, eb, start + PAGE_CACHE_SIZE,
 					     btrfs_header_generation(eb));
 					     btrfs_header_generation(eb));
 	BUG_ON(ret);
 	BUG_ON(ret);
@@ -427,6 +431,10 @@ static int btree_readpage_end_io_hook(struct page *page, u64 start, u64 end,
 	WARN_ON(len == 0);
 	WARN_ON(len == 0);
 
 
 	eb = alloc_extent_buffer(tree, start, len, page, GFP_NOFS);
 	eb = alloc_extent_buffer(tree, start, len, page, GFP_NOFS);
+	if (eb == NULL) {
+		ret = -EIO;
+		goto out;
+	}
 
 
 	found_start = btrfs_header_bytenr(eb);
 	found_start = btrfs_header_bytenr(eb);
 	if (found_start != start) {
 	if (found_start != start) {

+ 2 - 0
fs/btrfs/extent_io.c

@@ -3075,6 +3075,8 @@ static struct extent_buffer *__alloc_extent_buffer(struct extent_io_tree *tree,
 #endif
 #endif
 
 
 	eb = kmem_cache_zalloc(extent_buffer_cache, mask);
 	eb = kmem_cache_zalloc(extent_buffer_cache, mask);
+	if (eb == NULL)
+		return NULL;
 	eb->start = start;
 	eb->start = start;
 	eb->len = len;
 	eb->len = len;
 	spin_lock_init(&eb->lock);
 	spin_lock_init(&eb->lock);