]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Btrfs: check return value of bio_alloc() properly
authorTsutomu Itoh <t-itoh@jp.fujitsu.com>
Thu, 12 Apr 2012 20:03:56 +0000 (16:03 -0400)
committerChris Mason <chris.mason@oracle.com>
Thu, 12 Apr 2012 20:03:56 +0000 (16:03 -0400)
bio_alloc() has the possibility of returning NULL.
So, it is necessary to check the return value.

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

index d11afa67c7d86711b87cdb0913da1b98f9027da8..646f5e6f2566250ee879ee230815986dbd586253 100644 (file)
@@ -405,6 +405,7 @@ int btrfs_submit_compressed_write(struct inode *inode, u64 start,
                        bio_put(bio);
 
                        bio = compressed_bio_alloc(bdev, first_byte, GFP_NOFS);
+                       BUG_ON(!bio);
                        bio->bi_private = cb;
                        bio->bi_end_io = end_compressed_bio_write;
                        bio_add_page(bio, page, PAGE_CACHE_SIZE, 0);
@@ -687,6 +688,7 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
 
                        comp_bio = compressed_bio_alloc(bdev, cur_disk_byte,
                                                        GFP_NOFS);
+                       BUG_ON(!comp_bio);
                        comp_bio->bi_private = cb;
                        comp_bio->bi_end_io = end_compressed_bio_read;
 
index 59ec105444fe25cbf1da0dcc67d1651483e83eb1..4789770f8eaf00b9e7682f98fb983a161d317173 100644 (file)
@@ -2180,6 +2180,10 @@ static int bio_readpage_error(struct bio *failed_bio, struct page *page,
        }
 
        bio = bio_alloc(GFP_NOFS, 1);
+       if (!bio) {
+               free_io_failure(inode, failrec, 0);
+               return -EIO;
+       }
        bio->bi_private = state;
        bio->bi_end_io = failed_bio->bi_end_io;
        bio->bi_sector = failrec->logical >> 9;
index c9a2c1aef4bd0d21dd412c6be7ab639487dab57e..60f0e28db31eea09b96ac8c40f30573ccba59a69 100644 (file)
@@ -1044,6 +1044,8 @@ static int scrub_recheck_block(struct btrfs_fs_info *fs_info,
 
                BUG_ON(!page->page);
                bio = bio_alloc(GFP_NOFS, 1);
+               if (!bio)
+                       return -EIO;
                bio->bi_bdev = page->bdev;
                bio->bi_sector = page->physical >> 9;
                bio->bi_end_io = scrub_complete_bio_end_io;
@@ -1172,6 +1174,8 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,
                DECLARE_COMPLETION_ONSTACK(complete);
 
                bio = bio_alloc(GFP_NOFS, 1);
+               if (!bio)
+                       return -EIO;
                bio->bi_bdev = page_bad->bdev;
                bio->bi_sector = page_bad->physical >> 9;
                bio->bi_end_io = scrub_complete_bio_end_io;