diff options
author | Yoshinori Sano <yoshinori.sano@gmail.com> | 2011-02-15 07:01:42 -0500 |
---|---|---|
committer | root <Chris Mason chris.mason@oracle.com> | 2011-03-28 05:37:49 -0400 |
commit | dac97e516c617f9c797f64b0224050b70aea30c7 (patch) | |
tree | c5c7e7a40e649ee9beb9014b284d3a6e66fb94f2 /fs | |
parent | c622ae6085d0c6ad834213bbf1477eb311359078 (diff) |
Btrfs: fix uncheck memory allocations
To make Btrfs code more robust, several return value checks where memory
allocation can fail are introduced. I use BUG_ON where I don't know how
to handle the error properly, which increases the number of using the
notorious BUG_ON, though.
Signed-off-by: Yoshinori Sano <yoshinori.sano@gmail.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/compression.c | 6 | ||||
-rw-r--r-- | fs/btrfs/extent-tree.c | 4 | ||||
-rw-r--r-- | fs/btrfs/inode.c | 2 |
3 files changed, 12 insertions, 0 deletions
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 4d2110eafe29..992a4b92083e 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c | |||
@@ -340,6 +340,8 @@ int btrfs_submit_compressed_write(struct inode *inode, u64 start, | |||
340 | 340 | ||
341 | WARN_ON(start & ((u64)PAGE_CACHE_SIZE - 1)); | 341 | WARN_ON(start & ((u64)PAGE_CACHE_SIZE - 1)); |
342 | cb = kmalloc(compressed_bio_size(root, compressed_len), GFP_NOFS); | 342 | cb = kmalloc(compressed_bio_size(root, compressed_len), GFP_NOFS); |
343 | if (!cb) | ||
344 | return -ENOMEM; | ||
343 | atomic_set(&cb->pending_bios, 0); | 345 | atomic_set(&cb->pending_bios, 0); |
344 | cb->errors = 0; | 346 | cb->errors = 0; |
345 | cb->inode = inode; | 347 | cb->inode = inode; |
@@ -354,6 +356,10 @@ int btrfs_submit_compressed_write(struct inode *inode, u64 start, | |||
354 | bdev = BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev; | 356 | bdev = BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev; |
355 | 357 | ||
356 | bio = compressed_bio_alloc(bdev, first_byte, GFP_NOFS); | 358 | bio = compressed_bio_alloc(bdev, first_byte, GFP_NOFS); |
359 | if(!bio) { | ||
360 | kfree(cb); | ||
361 | return -ENOMEM; | ||
362 | } | ||
357 | bio->bi_private = cb; | 363 | bio->bi_private = cb; |
358 | bio->bi_end_io = end_compressed_bio_write; | 364 | bio->bi_end_io = end_compressed_bio_write; |
359 | atomic_inc(&cb->pending_bios); | 365 | atomic_inc(&cb->pending_bios); |
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 1efeda3b2f6f..cd0b69f57375 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -6978,6 +6978,10 @@ static noinline int get_new_locations(struct inode *reloc_inode, | |||
6978 | struct disk_extent *old = exts; | 6978 | struct disk_extent *old = exts; |
6979 | max *= 2; | 6979 | max *= 2; |
6980 | exts = kzalloc(sizeof(*exts) * max, GFP_NOFS); | 6980 | exts = kzalloc(sizeof(*exts) * max, GFP_NOFS); |
6981 | if (!exts) { | ||
6982 | ret = -ENOMEM; | ||
6983 | goto out; | ||
6984 | } | ||
6981 | memcpy(exts, old, sizeof(*exts) * nr); | 6985 | memcpy(exts, old, sizeof(*exts) * nr); |
6982 | if (old != *extents) | 6986 | if (old != *extents) |
6983 | kfree(old); | 6987 | kfree(old); |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 67fd6e9552d3..f739b256967e 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -290,6 +290,7 @@ static noinline int add_async_extent(struct async_cow *cow, | |||
290 | struct async_extent *async_extent; | 290 | struct async_extent *async_extent; |
291 | 291 | ||
292 | async_extent = kmalloc(sizeof(*async_extent), GFP_NOFS); | 292 | async_extent = kmalloc(sizeof(*async_extent), GFP_NOFS); |
293 | BUG_ON(!async_extent); | ||
293 | async_extent->start = start; | 294 | async_extent->start = start; |
294 | async_extent->ram_size = ram_size; | 295 | async_extent->ram_size = ram_size; |
295 | async_extent->compressed_size = compressed_size; | 296 | async_extent->compressed_size = compressed_size; |
@@ -388,6 +389,7 @@ again: | |||
388 | (BTRFS_I(inode)->flags & BTRFS_INODE_COMPRESS))) { | 389 | (BTRFS_I(inode)->flags & BTRFS_INODE_COMPRESS))) { |
389 | WARN_ON(pages); | 390 | WARN_ON(pages); |
390 | pages = kzalloc(sizeof(struct page *) * nr_pages, GFP_NOFS); | 391 | pages = kzalloc(sizeof(struct page *) * nr_pages, GFP_NOFS); |
392 | BUG_ON(!pages); | ||
391 | 393 | ||
392 | if (BTRFS_I(inode)->force_compress) | 394 | if (BTRFS_I(inode)->force_compress) |
393 | compress_type = BTRFS_I(inode)->force_compress; | 395 | compress_type = BTRFS_I(inode)->force_compress; |