btrfs: checking NULL or not in some functions
authorTsutomu Itoh <t-itoh@jp.fujitsu.com>
Tue, 1 Feb 2011 09:17:35 +0000 (09:17 +0000)
committerChris Mason <chris.mason@oracle.com>
Tue, 1 Feb 2011 12:16:37 +0000 (07:16 -0500)
Because NULL is returned when the memory allocation fails,
it is checked whether it is NULL.

Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
fs/btrfs/extent-tree.c
fs/btrfs/extent_io.c
fs/btrfs/tree-log.c

index f96641a93fc9c3b65da812caa2e08620b16f2f67..9de4ff03882acafe8d5f651c045899891464001a 100644 (file)
@@ -6496,6 +6496,8 @@ static noinline int relocate_inode_pages(struct inode *inode, u64 start,
        int ret = 0;
 
        ra = kzalloc(sizeof(*ra), GFP_NOFS);
+       if (!ra)
+               return -ENOMEM;
 
        mutex_lock(&inode->i_mutex);
        first_index = start >> PAGE_CACHE_SHIFT;
index 6411ed6ca449ae5ad5b4a15c12c8ca66d2ed82f8..8862dda46ff6ad5984be8519dbc9988a2e881f86 100644 (file)
@@ -1920,6 +1920,8 @@ static int submit_extent_page(int rw, struct extent_io_tree *tree,
                nr = bio_get_nr_vecs(bdev);
 
        bio = btrfs_bio_alloc(bdev, sector, nr, GFP_NOFS | __GFP_HIGH);
+       if (!bio)
+               return -ENOMEM;
 
        bio_add_page(bio, page, page_size, offset);
        bio->bi_end_io = end_io_func;
index 42dfc307704016d6ed4dc1ec434c0b686db73f7e..6d66e5caff97e50ac17215358c4a36696d4a9474 100644 (file)
@@ -2751,7 +2751,13 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
        log = root->log_root;
 
        path = btrfs_alloc_path();
+       if (!path)
+               return -ENOMEM;
        dst_path = btrfs_alloc_path();
+       if (!dst_path) {
+               btrfs_free_path(path);
+               return -ENOMEM;
+       }
 
        min_key.objectid = inode->i_ino;
        min_key.type = BTRFS_INODE_ITEM_KEY;