Skip to content

Commit e627ee7

Browse files
Tsutomu Itohchrismason-xx
authored andcommitted
Btrfs: check return value of bio_alloc() properly
bio_alloc() has the possibility of returning NULL. So, it is necessary to check the return value. Signed-off-by: Tsutomu Itoh <[email protected]> Signed-off-by: Chris Mason <[email protected]>
1 parent c6664b4 commit e627ee7

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

fs/btrfs/compression.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ int btrfs_submit_compressed_write(struct inode *inode, u64 start,
405405
bio_put(bio);
406406

407407
bio = compressed_bio_alloc(bdev, first_byte, GFP_NOFS);
408+
BUG_ON(!bio);
408409
bio->bi_private = cb;
409410
bio->bi_end_io = end_compressed_bio_write;
410411
bio_add_page(bio, page, PAGE_CACHE_SIZE, 0);
@@ -687,6 +688,7 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
687688

688689
comp_bio = compressed_bio_alloc(bdev, cur_disk_byte,
689690
GFP_NOFS);
691+
BUG_ON(!comp_bio);
690692
comp_bio->bi_private = cb;
691693
comp_bio->bi_end_io = end_compressed_bio_read;
692694

fs/btrfs/extent_io.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,6 +2180,10 @@ static int bio_readpage_error(struct bio *failed_bio, struct page *page,
21802180
}
21812181

21822182
bio = bio_alloc(GFP_NOFS, 1);
2183+
if (!bio) {
2184+
free_io_failure(inode, failrec, 0);
2185+
return -EIO;
2186+
}
21832187
bio->bi_private = state;
21842188
bio->bi_end_io = failed_bio->bi_end_io;
21852189
bio->bi_sector = failrec->logical >> 9;

fs/btrfs/scrub.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,8 @@ static int scrub_recheck_block(struct btrfs_fs_info *fs_info,
10441044

10451045
BUG_ON(!page->page);
10461046
bio = bio_alloc(GFP_NOFS, 1);
1047+
if (!bio)
1048+
return -EIO;
10471049
bio->bi_bdev = page->bdev;
10481050
bio->bi_sector = page->physical >> 9;
10491051
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,
11721174
DECLARE_COMPLETION_ONSTACK(complete);
11731175

11741176
bio = bio_alloc(GFP_NOFS, 1);
1177+
if (!bio)
1178+
return -EIO;
11751179
bio->bi_bdev = page_bad->bdev;
11761180
bio->bi_sector = page_bad->physical >> 9;
11771181
bio->bi_end_io = scrub_complete_bio_end_io;

0 commit comments

Comments
 (0)