Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 31e818fe authored by David Sterba's avatar David Sterba
Browse files

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: default avatarDavid Sterba <dsterba@suse.cz>
parent f8c269d7
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -2990,8 +2990,8 @@ static void __btrfsic_submit_bio(int rw, struct bio *bio)
			       (unsigned long long)bio->bi_iter.bi_sector,
			       dev_bytenr, bio->bi_bdev);

		mapped_datav = kmalloc(sizeof(*mapped_datav) * bio->bi_vcnt,
				       GFP_NOFS);
		mapped_datav = kmalloc_array(bio->bi_vcnt,
					     sizeof(*mapped_datav), GFP_NOFS);
		if (!mapped_datav)
			goto leave;
		cur_bytenr = dev_bytenr;
+1 −1
Original line number Diff line number Diff line
@@ -622,7 +622,7 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
	cb->orig_bio = bio;

	nr_pages = DIV_ROUND_UP(compressed_len, PAGE_CACHE_SIZE);
	cb->compressed_pages = kzalloc(sizeof(struct page *) * nr_pages,
	cb->compressed_pages = kcalloc(nr_pages, sizeof(struct page *),
				       GFP_NOFS);
	if (!cb->compressed_pages)
		goto fail1;
+4 −5
Original line number Diff line number Diff line
@@ -578,7 +578,7 @@ tree_mod_log_insert_move(struct btrfs_fs_info *fs_info,
	if (!tree_mod_need_log(fs_info, eb))
		return 0;

	tm_list = kzalloc(nr_items * sizeof(struct tree_mod_elem *), flags);
	tm_list = kcalloc(nr_items, sizeof(struct tree_mod_elem *), flags);
	if (!tm_list)
		return -ENOMEM;

@@ -677,7 +677,7 @@ tree_mod_log_insert_root(struct btrfs_fs_info *fs_info,

	if (log_removal && btrfs_header_level(old_root) > 0) {
		nritems = btrfs_header_nritems(old_root);
		tm_list = kzalloc(nritems * sizeof(struct tree_mod_elem *),
		tm_list = kcalloc(nritems, sizeof(struct tree_mod_elem *),
				  flags);
		if (!tm_list) {
			ret = -ENOMEM;
@@ -814,7 +814,7 @@ tree_mod_log_eb_copy(struct btrfs_fs_info *fs_info, struct extent_buffer *dst,
	if (btrfs_header_level(dst) == 0 && btrfs_header_level(src) == 0)
		return 0;

	tm_list = kzalloc(nr_items * 2 * sizeof(struct tree_mod_elem *),
	tm_list = kcalloc(nr_items * 2, sizeof(struct tree_mod_elem *),
			  GFP_NOFS);
	if (!tm_list)
		return -ENOMEM;
@@ -905,8 +905,7 @@ tree_mod_log_free_eb(struct btrfs_fs_info *fs_info, struct extent_buffer *eb)
		return 0;

	nritems = btrfs_header_nritems(eb);
	tm_list = kzalloc(nritems * sizeof(struct tree_mod_elem *),
			  GFP_NOFS);
	tm_list = kcalloc(nritems, sizeof(struct tree_mod_elem *), GFP_NOFS);
	if (!tm_list)
		return -ENOMEM;

+1 −1
Original line number Diff line number Diff line
@@ -302,7 +302,7 @@ static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf,
		offset += cur_len;
	}
	if (csum_size > sizeof(inline_result)) {
		result = kzalloc(csum_size * sizeof(char), GFP_NOFS);
		result = kzalloc(csum_size, GFP_NOFS);
		if (!result)
			return 1;
	} else {
+2 −2
Original line number Diff line number Diff line
@@ -185,8 +185,8 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root,
	nblocks = bio->bi_iter.bi_size >> inode->i_sb->s_blocksize_bits;
	if (!dst) {
		if (nblocks * csum_size > BTRFS_BIO_INLINE_CSUM_SIZE) {
			btrfs_bio->csum_allocated = kmalloc(nblocks * csum_size,
							    GFP_NOFS);
			btrfs_bio->csum_allocated = kmalloc_array(nblocks,
					csum_size, GFP_NOFS);
			if (!btrfs_bio->csum_allocated) {
				btrfs_free_path(path);
				return -ENOMEM;
Loading