diff options
author | David Sterba <dsterba@suse.cz> | 2015-02-20 12:00:26 -0500 |
---|---|---|
committer | David Sterba <dsterba@suse.cz> | 2015-03-03 11:23:58 -0500 |
commit | 31e818fe7375d60de9953051f7bd1615cebc3681 (patch) | |
tree | c096eb4b8398ada2c04ab459705f436bde969beb /fs/btrfs | |
parent | f8c269d7223f6b63cc5936eb191bc3b170d24342 (diff) |
btrfs: cleanup, use kmalloc_array/kcalloc array helpers
Convert kmalloc(nr * size, ..) to kmalloc_array that does additional
overflow checks, the zeroing variant is kcalloc.
Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/check-integrity.c | 4 | ||||
-rw-r--r-- | fs/btrfs/compression.c | 2 | ||||
-rw-r--r-- | fs/btrfs/ctree.c | 9 | ||||
-rw-r--r-- | fs/btrfs/disk-io.c | 2 | ||||
-rw-r--r-- | fs/btrfs/file-item.c | 4 | ||||
-rw-r--r-- | fs/btrfs/file.c | 2 | ||||
-rw-r--r-- | fs/btrfs/free-space-cache.c | 2 | ||||
-rw-r--r-- | fs/btrfs/inode.c | 2 | ||||
-rw-r--r-- | fs/btrfs/raid56.c | 3 | ||||
-rw-r--r-- | fs/btrfs/scrub.c | 5 | ||||
-rw-r--r-- | fs/btrfs/volumes.c | 4 |
11 files changed, 18 insertions, 21 deletions
diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c index d897ef803b3b..089d6fac01a7 100644 --- a/fs/btrfs/check-integrity.c +++ b/fs/btrfs/check-integrity.c | |||
@@ -2990,8 +2990,8 @@ static void __btrfsic_submit_bio(int rw, struct bio *bio) | |||
2990 | (unsigned long long)bio->bi_iter.bi_sector, | 2990 | (unsigned long long)bio->bi_iter.bi_sector, |
2991 | dev_bytenr, bio->bi_bdev); | 2991 | dev_bytenr, bio->bi_bdev); |
2992 | 2992 | ||
2993 | mapped_datav = kmalloc(sizeof(*mapped_datav) * bio->bi_vcnt, | 2993 | mapped_datav = kmalloc_array(bio->bi_vcnt, |
2994 | GFP_NOFS); | 2994 | sizeof(*mapped_datav), GFP_NOFS); |
2995 | if (!mapped_datav) | 2995 | if (!mapped_datav) |
2996 | goto leave; | 2996 | goto leave; |
2997 | cur_bytenr = dev_bytenr; | 2997 | cur_bytenr = dev_bytenr; |
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index e9df8862012c..ecacb7a2d422 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c | |||
@@ -622,7 +622,7 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, | |||
622 | cb->orig_bio = bio; | 622 | cb->orig_bio = bio; |
623 | 623 | ||
624 | nr_pages = DIV_ROUND_UP(compressed_len, PAGE_CACHE_SIZE); | 624 | nr_pages = DIV_ROUND_UP(compressed_len, PAGE_CACHE_SIZE); |
625 | cb->compressed_pages = kzalloc(sizeof(struct page *) * nr_pages, | 625 | cb->compressed_pages = kcalloc(nr_pages, sizeof(struct page *), |
626 | GFP_NOFS); | 626 | GFP_NOFS); |
627 | if (!cb->compressed_pages) | 627 | if (!cb->compressed_pages) |
628 | goto fail1; | 628 | goto fail1; |
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 993642199326..8595fdd50a22 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c | |||
@@ -578,7 +578,7 @@ tree_mod_log_insert_move(struct btrfs_fs_info *fs_info, | |||
578 | if (!tree_mod_need_log(fs_info, eb)) | 578 | if (!tree_mod_need_log(fs_info, eb)) |
579 | return 0; | 579 | return 0; |
580 | 580 | ||
581 | tm_list = kzalloc(nr_items * sizeof(struct tree_mod_elem *), flags); | 581 | tm_list = kcalloc(nr_items, sizeof(struct tree_mod_elem *), flags); |
582 | if (!tm_list) | 582 | if (!tm_list) |
583 | return -ENOMEM; | 583 | return -ENOMEM; |
584 | 584 | ||
@@ -677,7 +677,7 @@ tree_mod_log_insert_root(struct btrfs_fs_info *fs_info, | |||
677 | 677 | ||
678 | if (log_removal && btrfs_header_level(old_root) > 0) { | 678 | if (log_removal && btrfs_header_level(old_root) > 0) { |
679 | nritems = btrfs_header_nritems(old_root); | 679 | nritems = btrfs_header_nritems(old_root); |
680 | tm_list = kzalloc(nritems * sizeof(struct tree_mod_elem *), | 680 | tm_list = kcalloc(nritems, sizeof(struct tree_mod_elem *), |
681 | flags); | 681 | flags); |
682 | if (!tm_list) { | 682 | if (!tm_list) { |
683 | ret = -ENOMEM; | 683 | ret = -ENOMEM; |
@@ -814,7 +814,7 @@ tree_mod_log_eb_copy(struct btrfs_fs_info *fs_info, struct extent_buffer *dst, | |||
814 | if (btrfs_header_level(dst) == 0 && btrfs_header_level(src) == 0) | 814 | if (btrfs_header_level(dst) == 0 && btrfs_header_level(src) == 0) |
815 | return 0; | 815 | return 0; |
816 | 816 | ||
817 | tm_list = kzalloc(nr_items * 2 * sizeof(struct tree_mod_elem *), | 817 | tm_list = kcalloc(nr_items * 2, sizeof(struct tree_mod_elem *), |
818 | GFP_NOFS); | 818 | GFP_NOFS); |
819 | if (!tm_list) | 819 | if (!tm_list) |
820 | return -ENOMEM; | 820 | return -ENOMEM; |
@@ -905,8 +905,7 @@ tree_mod_log_free_eb(struct btrfs_fs_info *fs_info, struct extent_buffer *eb) | |||
905 | return 0; | 905 | return 0; |
906 | 906 | ||
907 | nritems = btrfs_header_nritems(eb); | 907 | nritems = btrfs_header_nritems(eb); |
908 | tm_list = kzalloc(nritems * sizeof(struct tree_mod_elem *), | 908 | tm_list = kcalloc(nritems, sizeof(struct tree_mod_elem *), GFP_NOFS); |
909 | GFP_NOFS); | ||
910 | if (!tm_list) | 909 | if (!tm_list) |
911 | return -ENOMEM; | 910 | return -ENOMEM; |
912 | 911 | ||
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 73b152138221..14e4a3e0f9b2 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -302,7 +302,7 @@ static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf, | |||
302 | offset += cur_len; | 302 | offset += cur_len; |
303 | } | 303 | } |
304 | if (csum_size > sizeof(inline_result)) { | 304 | if (csum_size > sizeof(inline_result)) { |
305 | result = kzalloc(csum_size * sizeof(char), GFP_NOFS); | 305 | result = kzalloc(csum_size, GFP_NOFS); |
306 | if (!result) | 306 | if (!result) |
307 | return 1; | 307 | return 1; |
308 | } else { | 308 | } else { |
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 84a2d1868271..3a4a7924fa38 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c | |||
@@ -185,8 +185,8 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, | |||
185 | nblocks = bio->bi_iter.bi_size >> inode->i_sb->s_blocksize_bits; | 185 | nblocks = bio->bi_iter.bi_size >> inode->i_sb->s_blocksize_bits; |
186 | if (!dst) { | 186 | if (!dst) { |
187 | if (nblocks * csum_size > BTRFS_BIO_INLINE_CSUM_SIZE) { | 187 | if (nblocks * csum_size > BTRFS_BIO_INLINE_CSUM_SIZE) { |
188 | btrfs_bio->csum_allocated = kmalloc(nblocks * csum_size, | 188 | btrfs_bio->csum_allocated = kmalloc_array(nblocks, |
189 | GFP_NOFS); | 189 | csum_size, GFP_NOFS); |
190 | if (!btrfs_bio->csum_allocated) { | 190 | if (!btrfs_bio->csum_allocated) { |
191 | btrfs_free_path(path); | 191 | btrfs_free_path(path); |
192 | return -ENOMEM; | 192 | return -ENOMEM; |
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 1e34bc00249f..e74abb3018d4 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -1481,7 +1481,7 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file, | |||
1481 | PAGE_CACHE_SIZE / (sizeof(struct page *))); | 1481 | PAGE_CACHE_SIZE / (sizeof(struct page *))); |
1482 | nrptrs = min(nrptrs, current->nr_dirtied_pause - current->nr_dirtied); | 1482 | nrptrs = min(nrptrs, current->nr_dirtied_pause - current->nr_dirtied); |
1483 | nrptrs = max(nrptrs, 8); | 1483 | nrptrs = max(nrptrs, 8); |
1484 | pages = kmalloc(nrptrs * sizeof(struct page *), GFP_KERNEL); | 1484 | pages = kmalloc_array(nrptrs, sizeof(struct page *), GFP_KERNEL); |
1485 | if (!pages) | 1485 | if (!pages) |
1486 | return -ENOMEM; | 1486 | return -ENOMEM; |
1487 | 1487 | ||
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index cb84923561e4..6e5d0abec6f9 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c | |||
@@ -298,7 +298,7 @@ static int io_ctl_init(struct io_ctl *io_ctl, struct inode *inode, | |||
298 | 298 | ||
299 | memset(io_ctl, 0, sizeof(struct io_ctl)); | 299 | memset(io_ctl, 0, sizeof(struct io_ctl)); |
300 | 300 | ||
301 | io_ctl->pages = kzalloc(sizeof(struct page *) * num_pages, GFP_NOFS); | 301 | io_ctl->pages = kcalloc(num_pages, sizeof(struct page *), GFP_NOFS); |
302 | if (!io_ctl->pages) | 302 | if (!io_ctl->pages) |
303 | return -ENOMEM; | 303 | return -ENOMEM; |
304 | 304 | ||
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 8564d8ce03de..21e4affafa3e 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -463,7 +463,7 @@ again: | |||
463 | */ | 463 | */ |
464 | if (inode_need_compress(inode)) { | 464 | if (inode_need_compress(inode)) { |
465 | WARN_ON(pages); | 465 | WARN_ON(pages); |
466 | pages = kzalloc(sizeof(struct page *) * nr_pages, GFP_NOFS); | 466 | pages = kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS); |
467 | if (!pages) { | 467 | if (!pages) { |
468 | /* just bail out to the uncompressed code */ | 468 | /* just bail out to the uncompressed code */ |
469 | goto cont; | 469 | goto cont; |
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c index 5264858ed768..b4634c30981e 100644 --- a/fs/btrfs/raid56.c +++ b/fs/btrfs/raid56.c | |||
@@ -1807,8 +1807,7 @@ static void __raid_recover_end_io(struct btrfs_raid_bio *rbio) | |||
1807 | int err; | 1807 | int err; |
1808 | int i; | 1808 | int i; |
1809 | 1809 | ||
1810 | pointers = kzalloc(rbio->real_stripes * sizeof(void *), | 1810 | pointers = kcalloc(rbio->real_stripes, sizeof(void *), GFP_NOFS); |
1811 | GFP_NOFS); | ||
1812 | if (!pointers) { | 1811 | if (!pointers) { |
1813 | err = -ENOMEM; | 1812 | err = -ENOMEM; |
1814 | goto cleanup_io; | 1813 | goto cleanup_io; |
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index db21f17df996..5a7d63cd9c25 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c | |||
@@ -964,9 +964,8 @@ static int scrub_handle_errored_block(struct scrub_block *sblock_to_check) | |||
964 | * the statistics. | 964 | * the statistics. |
965 | */ | 965 | */ |
966 | 966 | ||
967 | sblocks_for_recheck = kzalloc(BTRFS_MAX_MIRRORS * | 967 | sblocks_for_recheck = kcalloc(BTRFS_MAX_MIRRORS, |
968 | sizeof(*sblocks_for_recheck), | 968 | sizeof(*sblocks_for_recheck), GFP_NOFS); |
969 | GFP_NOFS); | ||
970 | if (!sblocks_for_recheck) { | 969 | if (!sblocks_for_recheck) { |
971 | spin_lock(&sctx->stat_lock); | 970 | spin_lock(&sctx->stat_lock); |
972 | sctx->stat.malloc_errors++; | 971 | sctx->stat.malloc_errors++; |
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 50bb7b8b17e8..5b77982ab6b1 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
@@ -4288,7 +4288,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, | |||
4288 | max_chunk_size = min(div_factor(fs_devices->total_rw_bytes, 1), | 4288 | max_chunk_size = min(div_factor(fs_devices->total_rw_bytes, 1), |
4289 | max_chunk_size); | 4289 | max_chunk_size); |
4290 | 4290 | ||
4291 | devices_info = kzalloc(sizeof(*devices_info) * fs_devices->rw_devices, | 4291 | devices_info = kcalloc(fs_devices->rw_devices, sizeof(*devices_info), |
4292 | GFP_NOFS); | 4292 | GFP_NOFS); |
4293 | if (!devices_info) | 4293 | if (!devices_info) |
4294 | return -ENOMEM; | 4294 | return -ENOMEM; |
@@ -5542,7 +5542,7 @@ int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree, | |||
5542 | rmap_len = map->stripe_len * nr_data_stripes(map); | 5542 | rmap_len = map->stripe_len * nr_data_stripes(map); |
5543 | } | 5543 | } |
5544 | 5544 | ||
5545 | buf = kzalloc(sizeof(u64) * map->num_stripes, GFP_NOFS); | 5545 | buf = kcalloc(map->num_stripes, sizeof(u64), GFP_NOFS); |
5546 | BUG_ON(!buf); /* -ENOMEM */ | 5546 | BUG_ON(!buf); /* -ENOMEM */ |
5547 | 5547 | ||
5548 | for (i = 0; i < map->num_stripes; i++) { | 5548 | for (i = 0; i < map->num_stripes; i++) { |