diff options
Diffstat (limited to 'fs/btrfs')
38 files changed, 147 insertions, 152 deletions
diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c index 6c6f3bb58f4e..cce7b2610364 100644 --- a/fs/btrfs/async-thread.c +++ b/fs/btrfs/async-thread.c @@ -85,7 +85,7 @@ struct btrfs_workqueue *btrfs_alloc_workqueue(struct btrfs_fs_info *fs_info, const char *name, unsigned int flags, int limit_active, int thresh) { - struct btrfs_workqueue *ret = kzalloc(sizeof(*ret), GFP_KERNEL); + struct btrfs_workqueue *ret = kzalloc_obj(*ret, GFP_KERNEL); if (!ret) return NULL; @@ -126,7 +126,7 @@ struct btrfs_workqueue *btrfs_alloc_ordered_workqueue( { struct btrfs_workqueue *ret; - ret = kzalloc(sizeof(*ret), GFP_KERNEL); + ret = kzalloc_obj(*ret, GFP_KERNEL); if (!ret) return NULL; diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index 9bb406f7dd30..78bf0cad1d2d 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -78,7 +78,7 @@ static int check_extent_in_eb(struct btrfs_backref_walk_ctx *ctx, } add_inode_elem: - e = kmalloc(sizeof(*e), GFP_NOFS); + e = kmalloc_obj(*e, GFP_NOFS); if (!e) return -ENOMEM; @@ -1805,7 +1805,7 @@ struct btrfs_backref_share_check_ctx *btrfs_alloc_backref_share_check_ctx(void) { struct btrfs_backref_share_check_ctx *ctx; - ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); + ctx = kzalloc_obj(*ctx, GFP_KERNEL); if (!ctx) return NULL; @@ -2797,7 +2797,7 @@ struct inode_fs_paths *init_ipath(s32 total_bytes, struct btrfs_root *fs_root, if (IS_ERR(fspath)) return ERR_CAST(fspath); - ifp = kmalloc(sizeof(*ifp), GFP_KERNEL); + ifp = kmalloc_obj(*ifp, GFP_KERNEL); if (!ifp) { kvfree(fspath); return ERR_PTR(-ENOMEM); @@ -2814,7 +2814,7 @@ struct btrfs_backref_iter *btrfs_backref_iter_alloc(struct btrfs_fs_info *fs_inf { struct btrfs_backref_iter *ret; - ret = kzalloc(sizeof(*ret), GFP_NOFS); + ret = kzalloc_obj(*ret, GFP_NOFS); if (!ret) return NULL; @@ -3024,7 +3024,7 @@ struct btrfs_backref_node *btrfs_backref_alloc_node( struct btrfs_backref_node *node; ASSERT(level >= 0 && level < BTRFS_MAX_LEVEL); - node = kzalloc(sizeof(*node), GFP_NOFS); + node = kzalloc_obj(*node, GFP_NOFS); if (!node) return node; @@ -3057,7 +3057,7 @@ struct btrfs_backref_edge *btrfs_backref_alloc_edge( { struct btrfs_backref_edge *edge; - edge = kzalloc(sizeof(*edge), GFP_NOFS); + edge = kzalloc_obj(*edge, GFP_NOFS); if (edge) cache->nr_edges++; return edge; diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index 4a1528803ff7..2a2a21aec817 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -709,7 +709,7 @@ static bool btrfs_wq_submit_bio(struct btrfs_bio *bbio, struct btrfs_fs_info *fs_info = bbio->inode->root->fs_info; struct async_submit_bio *async; - async = kmalloc(sizeof(*async), GFP_NOFS); + async = kmalloc_obj(*async, GFP_NOFS); if (!async) return false; diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 5f76683b3f21..c284f48cfae4 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -947,7 +947,7 @@ int btrfs_cache_block_group(struct btrfs_block_group *cache, bool wait) if (cache->flags & BTRFS_BLOCK_GROUP_REMAPPED) return 0; - caching_ctl = kzalloc(sizeof(*caching_ctl), GFP_NOFS); + caching_ctl = kzalloc_obj(*caching_ctl, GFP_NOFS); if (!caching_ctl) return -ENOMEM; @@ -2312,12 +2312,11 @@ static struct btrfs_block_group *btrfs_create_block_group( { struct btrfs_block_group *cache; - cache = kzalloc(sizeof(*cache), GFP_NOFS); + cache = kzalloc_obj(*cache, GFP_NOFS); if (!cache) return NULL; - cache->free_space_ctl = kzalloc(sizeof(*cache->free_space_ctl), - GFP_NOFS); + cache->free_space_ctl = kzalloc_obj(*cache->free_space_ctl, GFP_NOFS); if (!cache->free_space_ctl) { kfree(cache); return NULL; diff --git a/fs/btrfs/block-rsv.c b/fs/btrfs/block-rsv.c index 93c371db8731..6064dd00d041 100644 --- a/fs/btrfs/block-rsv.c +++ b/fs/btrfs/block-rsv.c @@ -192,7 +192,7 @@ struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_fs_info *fs_info, { struct btrfs_block_rsv *block_rsv; - block_rsv = kmalloc(sizeof(*block_rsv), GFP_NOFS); + block_rsv = kmalloc_obj(*block_rsv, GFP_NOFS); if (!block_rsv) return NULL; diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 1e7174ad32e2..7fde7698c331 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -662,7 +662,7 @@ static struct list_head *alloc_heuristic_ws(struct btrfs_fs_info *fs_info) { struct heuristic_ws *ws; - ws = kzalloc(sizeof(*ws), GFP_KERNEL); + ws = kzalloc_obj(*ws, GFP_KERNEL); if (!ws) return ERR_PTR(-ENOMEM); @@ -670,11 +670,11 @@ static struct list_head *alloc_heuristic_ws(struct btrfs_fs_info *fs_info) if (!ws->sample) goto fail; - ws->bucket = kcalloc(BUCKET_SIZE, sizeof(*ws->bucket), GFP_KERNEL); + ws->bucket = kzalloc_objs(*ws->bucket, BUCKET_SIZE, GFP_KERNEL); if (!ws->bucket) goto fail; - ws->bucket_b = kcalloc(BUCKET_SIZE, sizeof(*ws->bucket_b), GFP_KERNEL); + ws->bucket_b = kzalloc_objs(*ws->bucket_b, BUCKET_SIZE, GFP_KERNEL); if (!ws->bucket_b) goto fail; @@ -734,7 +734,7 @@ static int alloc_workspace_manager(struct btrfs_fs_info *fs_info, struct list_head *workspace; ASSERT(fs_info->compr_wsm[type] == NULL); - gwsm = kzalloc(sizeof(*gwsm), GFP_KERNEL); + gwsm = kzalloc_obj(*gwsm, GFP_KERNEL); if (!gwsm) return -ENOMEM; diff --git a/fs/btrfs/defrag.c b/fs/btrfs/defrag.c index ecf05cd64696..7e2db5d3a4d4 100644 --- a/fs/btrfs/defrag.c +++ b/fs/btrfs/defrag.c @@ -1091,7 +1091,7 @@ add: } /* Allocate new defrag_target_range */ - new = kmalloc(sizeof(*new), GFP_NOFS); + new = kmalloc_obj(*new, GFP_NOFS); if (!new) { btrfs_free_extent_map(em); ret = -ENOMEM; @@ -1206,7 +1206,7 @@ static int defrag_one_range(struct btrfs_inode *inode, u64 start, u32 len, ASSERT(nr_pages <= CLUSTER_SIZE / PAGE_SIZE); ASSERT(IS_ALIGNED(start, sectorsize) && IS_ALIGNED(len, sectorsize)); - folios = kcalloc(nr_pages, sizeof(struct folio *), GFP_NOFS); + folios = kzalloc_objs(struct folio *, nr_pages, GFP_NOFS); if (!folios) return -ENOMEM; diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c index 1739a0b29c49..d97bbbd045e0 100644 --- a/fs/btrfs/delayed-inode.c +++ b/fs/btrfs/delayed-inode.c @@ -349,7 +349,7 @@ static struct btrfs_delayed_item *btrfs_alloc_delayed_item(u16 data_len, { struct btrfs_delayed_item *item; - item = kmalloc(struct_size(item, data, data_len), GFP_NOFS); + item = kmalloc_flex(*item, data, data_len, GFP_NOFS); if (item) { item->data_len = data_len; item->type = type; @@ -1384,7 +1384,7 @@ static int btrfs_wq_run_delayed_node(struct btrfs_delayed_root *delayed_root, { struct btrfs_async_delayed_work *async_work; - async_work = kmalloc(sizeof(*async_work), GFP_NOFS); + async_work = kmalloc_obj(*async_work, GFP_NOFS); if (!async_work) return -ENOMEM; diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index e8bc37453336..3766ff29fbbb 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -1027,7 +1027,7 @@ static int add_delayed_ref(struct btrfs_trans_handle *trans, delayed_refs = &trans->transaction->delayed_refs; if (btrfs_qgroup_full_accounting(fs_info) && !generic_ref->skip_qgroup) { - record = kzalloc(sizeof(*record), GFP_NOFS); + record = kzalloc_obj(*record, GFP_NOFS); if (!record) { ret = -ENOMEM; goto free_head_ref; diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 13e400046c87..f6fa15a1193f 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -605,7 +605,7 @@ static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info, { struct btrfs_root *root; - root = kzalloc(sizeof(*root), flags); + root = kzalloc_obj(*root, flags); if (!root) return NULL; diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index 73571d5d3d5a..a9b0b596429d 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h @@ -200,7 +200,7 @@ static inline struct extent_changeset *extent_changeset_alloc(void) { struct extent_changeset *ret; - ret = kmalloc(sizeof(*ret), GFP_KERNEL); + ret = kmalloc_obj(*ret, GFP_KERNEL); if (!ret) return NULL; diff --git a/fs/btrfs/fiemap.c b/fs/btrfs/fiemap.c index f2eaaef8422b..2e113f81a2d8 100644 --- a/fs/btrfs/fiemap.c +++ b/fs/btrfs/fiemap.c @@ -646,9 +646,8 @@ static int extent_fiemap(struct btrfs_inode *inode, int ret; cache.entries_size = PAGE_SIZE / sizeof(struct btrfs_fiemap_entry); - cache.entries = kmalloc_array(cache.entries_size, - sizeof(struct btrfs_fiemap_entry), - GFP_KERNEL); + cache.entries = kmalloc_objs(struct btrfs_fiemap_entry, + cache.entries_size, GFP_KERNEL); backref_ctx = btrfs_alloc_backref_share_check_ctx(); path = btrfs_alloc_path(); if (!cache.entries || !backref_ctx || !path) { diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 7bd715442f3e..927324a2175a 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -845,7 +845,7 @@ int btrfs_csum_one_bio(struct btrfs_bio *bbio, bool async) */ int btrfs_alloc_dummy_sum(struct btrfs_bio *bbio) { - bbio->sums = kmalloc(sizeof(*bbio->sums), GFP_NOFS); + bbio->sums = kmalloc_obj(*bbio->sums, GFP_NOFS); if (!bbio->sums) return -ENOMEM; bbio->sums->len = bbio->bio.bi_iter.bi_size; diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index acaa3dbd2b7b..21cb45e23a6f 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -2842,7 +2842,7 @@ static int add_falloc_range(struct list_head *head, u64 start, u64 len) } } - range = kmalloc(sizeof(*range), GFP_KERNEL); + range = kmalloc_obj(*range, GFP_KERNEL); if (!range) return -ENOMEM; range->start = start; @@ -3572,7 +3572,7 @@ static loff_t find_desired_extent(struct file *file, loff_t offset, int whence) */ private = NULL; } else if (!private) { - private = kzalloc(sizeof(*private), GFP_KERNEL); + private = kzalloc_obj(*private, GFP_KERNEL); /* * No worries if memory allocation failed. * The private structure is used only for speeding up multiple diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index cc075a460a22..ab22e4f9ffdd 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -388,7 +388,7 @@ static int io_ctl_init(struct btrfs_io_ctl *io_ctl, struct inode *inode, memset(io_ctl, 0, sizeof(struct btrfs_io_ctl)); - io_ctl->pages = kcalloc(num_pages, sizeof(struct page *), GFP_NOFS); + io_ctl->pages = kzalloc_objs(struct page *, num_pages, GFP_NOFS); if (!io_ctl->pages) return -ENOMEM; diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 5bbbce2224a1..da4be08d133e 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -781,7 +781,7 @@ static int add_async_extent(struct async_chunk *cow, u64 start, u64 ram_size, { struct async_extent *async_extent; - async_extent = kmalloc(sizeof(*async_extent), GFP_NOFS); + async_extent = kmalloc_obj(*async_extent, GFP_NOFS); if (!async_extent) return -ENOMEM; ASSERT(ram_size < U32_MAX); @@ -1692,7 +1692,7 @@ static bool run_delalloc_compressed(struct btrfs_inode *inode, const blk_opf_t write_flags = wbc_to_write_flags(wbc); nofs_flag = memalloc_nofs_save(); - ctx = kvmalloc(struct_size(ctx, chunks, num_chunks), GFP_KERNEL); + ctx = kvmalloc_flex(*ctx, chunks, num_chunks, GFP_KERNEL); memalloc_nofs_restore(nofs_flag); if (!ctx) return false; @@ -2991,7 +2991,7 @@ int btrfs_writepage_cow_fixup(struct folio *folio) if (folio_test_checked(folio)) return -EAGAIN; - fixup = kzalloc(sizeof(*fixup), GFP_NOFS); + fixup = kzalloc_obj(*fixup, GFP_NOFS); if (!fixup) return -EAGAIN; @@ -3967,7 +3967,7 @@ static int btrfs_init_file_extent_tree(struct btrfs_inode *inode) if (btrfs_is_free_space_inode(inode)) return 0; - inode->file_extent_tree = kmalloc(sizeof(struct extent_io_tree), GFP_KERNEL); + inode->file_extent_tree = kmalloc_obj(struct extent_io_tree, GFP_KERNEL); if (!inode->file_extent_tree) return -ENOMEM; @@ -6221,7 +6221,7 @@ static int btrfs_opendir(struct inode *inode, struct file *file) if (ret) return ret; - private = kzalloc(sizeof(struct btrfs_file_private), GFP_KERNEL); + private = kzalloc_obj(struct btrfs_file_private, GFP_KERNEL); if (!private) return -ENOMEM; private->last_index = last_index; @@ -8839,7 +8839,7 @@ static struct btrfs_delalloc_work *btrfs_alloc_delalloc_work(struct inode *inode { struct btrfs_delalloc_work *work; - work = kmalloc(sizeof(*work), GFP_NOFS); + work = kmalloc_obj(*work, GFP_NOFS); if (!work) return NULL; @@ -9538,7 +9538,7 @@ int btrfs_encoded_read_regular_fill_pages(struct btrfs_inode *inode, * needs longer time span. */ if (uring_ctx) { - priv = kmalloc(sizeof(struct btrfs_encoded_read_private), GFP_NOFS); + priv = kmalloc_obj(struct btrfs_encoded_read_private, GFP_NOFS); if (!priv) return -ENOMEM; } else { @@ -9608,7 +9608,7 @@ ssize_t btrfs_encoded_read_regular(struct kiocb *iocb, struct iov_iter *iter, ssize_t ret; nr_pages = DIV_ROUND_UP(disk_io_size, PAGE_SIZE); - pages = kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS); + pages = kzalloc_objs(struct page *, nr_pages, GFP_NOFS); if (!pages) return -ENOMEM; ret = btrfs_alloc_page_array(nr_pages, pages, false); @@ -10092,7 +10092,7 @@ static int btrfs_add_swapfile_pin(struct inode *inode, void *ptr, struct rb_node **p; struct rb_node *parent = NULL; - sp = kmalloc(sizeof(*sp), GFP_NOFS); + sp = kmalloc_obj(*sp, GFP_NOFS); if (!sp) return -ENOMEM; sp->ptr = ptr; diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index a6cc2d3b414c..af8a9c698b07 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -726,15 +726,15 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir, return -ETXTBSY; } - pending_snapshot = kzalloc(sizeof(*pending_snapshot), GFP_KERNEL); + pending_snapshot = kzalloc_obj(*pending_snapshot, GFP_KERNEL); if (!pending_snapshot) return -ENOMEM; ret = get_anon_bdev(&pending_snapshot->anon_dev); if (ret < 0) goto free_pending; - pending_snapshot->root_item = kzalloc(sizeof(struct btrfs_root_item), - GFP_KERNEL); + pending_snapshot->root_item = kzalloc_obj(struct btrfs_root_item, + GFP_KERNEL); pending_snapshot->path = btrfs_alloc_path(); if (!pending_snapshot->root_item || !pending_snapshot->path) { ret = -ENOMEM; @@ -1958,7 +1958,7 @@ static int btrfs_ioctl_get_subvol_info(struct inode *inode, void __user *argp) if (!path) return -ENOMEM; - subvol_info = kzalloc(sizeof(*subvol_info), GFP_KERNEL); + subvol_info = kzalloc_obj(*subvol_info, GFP_KERNEL); if (!subvol_info) { btrfs_free_path(path); return -ENOMEM; @@ -3423,7 +3423,7 @@ static long btrfs_ioctl_balance(struct file *file, void __user *arg) goto out_unlock; } - bctl = kzalloc(sizeof(*bctl), GFP_KERNEL); + bctl = kzalloc_obj(*bctl, GFP_KERNEL); if (!bctl) { ret = -ENOMEM; goto out_unlock; @@ -3604,7 +3604,7 @@ static long btrfs_ioctl_qgroup_assign(struct file *file, void __user *arg) } if (sa->assign) { - prealloc = kzalloc(sizeof(*prealloc), GFP_KERNEL); + prealloc = kzalloc_obj(*prealloc, GFP_KERNEL); if (!prealloc) { ret = -ENOMEM; goto out; @@ -3924,7 +3924,7 @@ static long btrfs_ioctl_set_received_subvol_32(struct file *file, if (IS_ERR(args32)) return PTR_ERR(args32); - args64 = kmalloc(sizeof(*args64), GFP_KERNEL); + args64 = kmalloc_obj(*args64, GFP_KERNEL); if (!args64) { ret = -ENOMEM; goto out; @@ -4234,7 +4234,7 @@ static int _btrfs_ioctl_send(struct btrfs_root *root, void __user *argp, bool co ret = copy_from_user(&args32, argp, sizeof(args32)); if (ret) return -EFAULT; - arg = kzalloc(sizeof(*arg), GFP_KERNEL); + arg = kzalloc_obj(*arg, GFP_KERNEL); if (!arg) return -ENOMEM; arg->send_fd = args32.send_fd; @@ -4588,7 +4588,7 @@ static int btrfs_uring_read_extent(struct kiocb *iocb, struct iov_iter *iter, int ret; nr_pages = DIV_ROUND_UP(disk_io_size, PAGE_SIZE); - pages = kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS); + pages = kzalloc_objs(struct page *, nr_pages, GFP_NOFS); if (!pages) return -ENOMEM; ret = btrfs_alloc_page_array(nr_pages, pages, 0); @@ -4597,7 +4597,7 @@ static int btrfs_uring_read_extent(struct kiocb *iocb, struct iov_iter *iter, goto out_fail; } - priv = kmalloc(sizeof(*priv), GFP_NOFS); + priv = kmalloc_obj(*priv, GFP_NOFS); if (!priv) { ret = -ENOMEM; goto out_fail; @@ -4682,7 +4682,7 @@ static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int issue } if (!data) { - data = kzalloc(sizeof(*data), GFP_NOFS); + data = kzalloc_obj(*data, GFP_NOFS); if (!data) { ret = -ENOMEM; goto out_acct; @@ -4817,7 +4817,7 @@ static int btrfs_uring_encoded_write(struct io_uring_cmd *cmd, unsigned int issu } if (!data) { - data = kzalloc(sizeof(*data), GFP_NOFS); + data = kzalloc_obj(*data, GFP_NOFS); if (!data) { ret = -ENOMEM; goto out_acct; diff --git a/fs/btrfs/lru_cache.c b/fs/btrfs/lru_cache.c index fd88af17d8d9..f5a053b905e1 100644 --- a/fs/btrfs/lru_cache.c +++ b/fs/btrfs/lru_cache.c @@ -111,7 +111,7 @@ int btrfs_lru_cache_store(struct btrfs_lru_cache *cache, struct list_head *head; int ret; - head = kmalloc(sizeof(*head), gfp); + head = kmalloc_obj(*head, gfp); if (!head) return -ENOMEM; diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c index 8e20497afffe..e37d986f26be 100644 --- a/fs/btrfs/lzo.c +++ b/fs/btrfs/lzo.c @@ -88,7 +88,7 @@ struct list_head *lzo_alloc_workspace(struct btrfs_fs_info *fs_info) { struct workspace *workspace; - workspace = kzalloc(sizeof(*workspace), GFP_KERNEL); + workspace = kzalloc_obj(*workspace, GFP_KERNEL); if (!workspace) return ERR_PTR(-ENOMEM); diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 38adadb936dc..6bd8739097d3 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -495,7 +495,7 @@ int btrfs_read_qgroup_config(struct btrfs_fs_info *fs_info) struct btrfs_qgroup *prealloc; struct btrfs_root *tree_root = fs_info->tree_root; - prealloc = kzalloc(sizeof(*prealloc), GFP_KERNEL); + prealloc = kzalloc_obj(*prealloc, GFP_KERNEL); if (!prealloc) { ret = -ENOMEM; goto out; @@ -585,7 +585,7 @@ next1: goto next2; } - list = kzalloc(sizeof(*list), GFP_KERNEL); + list = kzalloc_obj(*list, GFP_KERNEL); if (!list) { ret = -ENOMEM; goto out; @@ -1140,7 +1140,7 @@ int btrfs_quota_enable(struct btrfs_fs_info *fs_info, /* We should not have a stray @prealloc pointer. */ ASSERT(prealloc == NULL); - prealloc = kzalloc(sizeof(*prealloc), GFP_NOFS); + prealloc = kzalloc_obj(*prealloc, GFP_NOFS); if (unlikely(!prealloc)) { ret = -ENOMEM; btrfs_abort_transaction(trans, ret); @@ -1197,7 +1197,7 @@ out_add_root: } ASSERT(prealloc == NULL); - prealloc = kzalloc(sizeof(*prealloc), GFP_NOFS); + prealloc = kzalloc_obj(*prealloc, GFP_NOFS); if (!prealloc) { ret = -ENOMEM; goto out_free_path; @@ -1693,7 +1693,7 @@ int btrfs_create_qgroup(struct btrfs_trans_handle *trans, u64 qgroupid) goto out; } - prealloc = kzalloc(sizeof(*prealloc), GFP_NOFS); + prealloc = kzalloc_obj(*prealloc, GFP_NOFS); if (!prealloc) { ret = -ENOMEM; goto out; @@ -2147,7 +2147,7 @@ int btrfs_qgroup_trace_extent(struct btrfs_trans_handle *trans, u64 bytenr, if (!btrfs_qgroup_full_accounting(fs_info) || bytenr == 0 || num_bytes == 0) return 0; - record = kzalloc(sizeof(*record), GFP_NOFS); + record = kzalloc_obj(*record, GFP_NOFS); if (!record) return -ENOMEM; @@ -3346,7 +3346,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid, if (!btrfs_qgroup_enabled(fs_info)) return 0; - prealloc = kzalloc(sizeof(*prealloc), GFP_NOFS); + prealloc = kzalloc_obj(*prealloc, GFP_NOFS); if (!prealloc) return -ENOMEM; @@ -3428,16 +3428,15 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid, } ret = 0; - qlist_prealloc = kcalloc(inherit->num_qgroups, - sizeof(struct btrfs_qgroup_list *), - GFP_NOFS); + qlist_prealloc = kzalloc_objs(struct btrfs_qgroup_list *, + inherit->num_qgroups, GFP_NOFS); if (!qlist_prealloc) { ret = -ENOMEM; goto out; } for (int i = 0; i < inherit->num_qgroups; i++) { - qlist_prealloc[i] = kzalloc(sizeof(struct btrfs_qgroup_list), - GFP_NOFS); + qlist_prealloc[i] = kzalloc_obj(struct btrfs_qgroup_list, + GFP_NOFS); if (!qlist_prealloc[i]) { ret = -ENOMEM; goto out; @@ -4753,7 +4752,7 @@ int btrfs_qgroup_add_swapped_blocks(struct btrfs_root *subvol_root, return -EUCLEAN; } - block = kmalloc(sizeof(*block), GFP_NOFS); + block = kmalloc_obj(*block, GFP_NOFS); if (!block) { ret = -ENOMEM; goto out; diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c index baadaaa189c0..8112122c13e6 100644 --- a/fs/btrfs/raid56.c +++ b/fs/btrfs/raid56.c @@ -208,7 +208,7 @@ int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info) * Try harder to allocate and fallback to vmalloc to lower the chance * of a failing mount. */ - table = kvzalloc(struct_size(table, table, num_entries), GFP_KERNEL); + table = kvzalloc_flex(*table, table, num_entries, GFP_KERNEL); if (!table) return -ENOMEM; @@ -1090,13 +1090,15 @@ static struct btrfs_raid_bio *alloc_rbio(struct btrfs_fs_info *fs_info, ASSERT(real_stripes >= 2); ASSERT(real_stripes <= U8_MAX); - rbio = kzalloc(sizeof(*rbio), GFP_NOFS); + rbio = kzalloc_obj(*rbio, GFP_NOFS); if (!rbio) return ERR_PTR(-ENOMEM); - rbio->stripe_pages = kcalloc(num_pages, sizeof(struct page *), - GFP_NOFS); - rbio->bio_paddrs = kcalloc(num_sectors * sector_nsteps, sizeof(phys_addr_t), GFP_NOFS); - rbio->stripe_paddrs = kcalloc(num_sectors * sector_nsteps, sizeof(phys_addr_t), GFP_NOFS); + rbio->stripe_pages = kzalloc_objs(struct page *, num_pages, GFP_NOFS); + rbio->bio_paddrs = kzalloc_objs(phys_addr_t, + num_sectors * sector_nsteps, GFP_NOFS); + rbio->stripe_paddrs = kzalloc_objs(phys_addr_t, + num_sectors * sector_nsteps, + GFP_NOFS); rbio->finish_pointers = kcalloc(real_stripes, sizeof(void *), GFP_NOFS); rbio->error_bitmap = bitmap_zalloc(num_sectors, GFP_NOFS); rbio->stripe_uptodate_bitmap = bitmap_zalloc(num_sectors, GFP_NOFS); diff --git a/fs/btrfs/ref-verify.c b/fs/btrfs/ref-verify.c index e9224145d754..f78369ff2a66 100644 --- a/fs/btrfs/ref-verify.c +++ b/fs/btrfs/ref-verify.c @@ -249,8 +249,8 @@ static struct block_entry *add_block_entry(struct btrfs_fs_info *fs_info, struct block_entry *be = NULL, *exist; struct root_entry *re = NULL; - re = kzalloc(sizeof(struct root_entry), GFP_NOFS); - be = kzalloc(sizeof(struct block_entry), GFP_NOFS); + re = kzalloc_obj(struct root_entry, GFP_NOFS); + be = kzalloc_obj(struct block_entry, GFP_NOFS); if (!be || !re) { kfree(re); kfree(be); @@ -298,7 +298,7 @@ static int add_tree_block(struct btrfs_fs_info *fs_info, u64 ref_root, struct root_entry *re; struct ref_entry *ref = NULL, *exist; - ref = kmalloc(sizeof(struct ref_entry), GFP_NOFS); + ref = kmalloc_obj(struct ref_entry, GFP_NOFS); if (!ref) return -ENOMEM; @@ -343,7 +343,7 @@ static int add_shared_data_ref(struct btrfs_fs_info *fs_info, struct block_entry *be; struct ref_entry *ref; - ref = kzalloc(sizeof(struct ref_entry), GFP_NOFS); + ref = kzalloc_obj(struct ref_entry, GFP_NOFS); if (!ref) return -ENOMEM; be = add_block_entry(fs_info, bytenr, num_bytes, 0); @@ -378,7 +378,7 @@ static int add_extent_data_ref(struct btrfs_fs_info *fs_info, u64 offset = btrfs_extent_data_ref_offset(leaf, dref); u32 num_refs = btrfs_extent_data_ref_count(leaf, dref); - ref = kzalloc(sizeof(struct ref_entry), GFP_NOFS); + ref = kzalloc_obj(struct ref_entry, GFP_NOFS); if (!ref) return -ENOMEM; be = add_block_entry(fs_info, bytenr, num_bytes, ref_root); @@ -680,8 +680,8 @@ int btrfs_ref_tree_mod(struct btrfs_fs_info *fs_info, } metadata = owner < BTRFS_FIRST_FREE_OBJECTID; - ref = kzalloc(sizeof(struct ref_entry), GFP_NOFS); - ra = kmalloc(sizeof(struct ref_action), GFP_NOFS); + ref = kzalloc_obj(struct ref_entry, GFP_NOFS); + ra = kmalloc_obj(struct ref_action, GFP_NOFS); if (!ra || !ref) { kfree(ref); kfree(ra); @@ -755,7 +755,7 @@ int btrfs_ref_tree_mod(struct btrfs_fs_info *fs_info, struct root_entry *tmp; if (!parent) { - re = kmalloc(sizeof(struct root_entry), GFP_NOFS); + re = kmalloc_obj(struct root_entry, GFP_NOFS); if (!re) { kfree(ref); kfree(ra); diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index fcd0a2ba3554..95db7c48fbad 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -483,7 +483,7 @@ static int __add_reloc_root(struct btrfs_root *root) struct mapping_node *node; struct reloc_control *rc = fs_info->reloc_ctl; - node = kmalloc(sizeof(*node), GFP_NOFS); + node = kmalloc_obj(*node, GFP_NOFS); if (!node) return -ENOMEM; @@ -3115,7 +3115,7 @@ static int add_tree_block(struct reloc_control *rc, BUG_ON(level == -1); - block = kmalloc(sizeof(*block), GFP_NOFS); + block = kmalloc_obj(*block, GFP_NOFS); if (!block) return -ENOMEM; @@ -3813,7 +3813,7 @@ static struct reloc_control *alloc_reloc_control(struct btrfs_fs_info *fs_info) { struct reloc_control *rc; - rc = kzalloc(sizeof(*rc), GFP_NOFS); + rc = kzalloc_obj(*rc, GFP_NOFS); if (!rc) return NULL; @@ -4042,7 +4042,7 @@ static int copy_remapped_data(struct btrfs_fs_info *fs_info, u64 old_addr, struct reloc_io_private priv; unsigned int nr_pages = DIV_ROUND_UP(length, PAGE_SIZE); - pages = kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS); + pages = kzalloc_objs(struct page *, nr_pages, GFP_NOFS); if (!pages) return -ENOMEM; diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index 2a64e2d50ced..dfed8eaf938e 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -373,9 +373,8 @@ static int init_scrub_stripe(struct btrfs_fs_info *fs_info, if (ret < 0) goto error; - stripe->sectors = kcalloc(stripe->nr_sectors, - sizeof(struct scrub_sector_verification), - GFP_KERNEL); + stripe->sectors = kzalloc_objs(struct scrub_sector_verification, + stripe->nr_sectors, GFP_KERNEL); if (!stripe->sectors) goto error; @@ -456,7 +455,7 @@ static noinline_for_stack struct scrub_ctx *scrub_setup_ctx( /* Since sctx has inline 128 stripes, it can go beyond 64K easily. Use * kvzalloc(). */ - sctx = kvzalloc(sizeof(*sctx), GFP_KERNEL); + sctx = kvzalloc_obj(*sctx, GFP_KERNEL); if (!sctx) goto nomem; refcount_set(&sctx->refs, 1); @@ -2474,9 +2473,9 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx, if (profile & BTRFS_BLOCK_GROUP_RAID56_MASK) { ASSERT(sctx->raid56_data_stripes == NULL); - sctx->raid56_data_stripes = kcalloc(nr_data_stripes(map), - sizeof(struct scrub_stripe), - GFP_KERNEL); + sctx->raid56_data_stripes = kzalloc_objs(struct scrub_stripe, + nr_data_stripes(map), + GFP_KERNEL); if (!sctx->raid56_data_stripes) { ret = -ENOMEM; goto out; diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 3dcfdba018b5..23b0b06ac71c 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -450,7 +450,7 @@ static struct fs_path *fs_path_alloc(void) { struct fs_path *p; - p = kmalloc(sizeof(*p), GFP_KERNEL); + p = kmalloc_obj(*p, GFP_KERNEL); if (!p) return NULL; init_path(p); @@ -1429,7 +1429,7 @@ static void store_backref_cache(u64 leaf_bytenr, const struct ulist *root_ids, * fs_info->commit_root_sem (at iterate_extent_inodes()), so must do a * NOFS allocation. */ - new_entry = kmalloc(sizeof(struct backref_cache_entry), GFP_NOFS); + new_entry = kmalloc_obj(struct backref_cache_entry, GFP_NOFS); /* No worries, cache is optional. */ if (!new_entry) return; @@ -2743,7 +2743,7 @@ static int cache_dir_utimes(struct send_ctx *sctx, u64 dir, u64 gen) return 0; /* Caching is optional, don't fail if we can't allocate memory. */ - entry = kmalloc(sizeof(*entry), GFP_KERNEL); + entry = kmalloc_obj(*entry, GFP_KERNEL); if (!entry) return send_utimes(sctx, dir, gen); @@ -2870,7 +2870,7 @@ static void cache_dir_created(struct send_ctx *sctx, u64 dir) int ret; /* Caching is optional, ignore any failures. */ - entry = kmalloc(sizeof(*entry), GFP_KERNEL); + entry = kmalloc_obj(*entry, GFP_KERNEL); if (!entry) return; @@ -2974,7 +2974,7 @@ static struct recorded_ref *recorded_ref_alloc(void) { struct recorded_ref *ref; - ref = kzalloc(sizeof(*ref), GFP_KERNEL); + ref = kzalloc_obj(*ref, GFP_KERNEL); if (!ref) return NULL; RB_CLEAR_NODE(&ref->node); @@ -3083,7 +3083,7 @@ static struct orphan_dir_info *add_orphan_dir_info(struct send_ctx *sctx, return entry; } - odi = kmalloc(sizeof(*odi), GFP_KERNEL); + odi = kmalloc_obj(*odi, GFP_KERNEL); if (!odi) return ERR_PTR(-ENOMEM); odi->ino = dir_ino; @@ -3284,7 +3284,7 @@ static int add_waiting_dir_move(struct send_ctx *sctx, u64 ino, bool orphanized) struct rb_node *parent = NULL; struct waiting_dir_move *entry, *dm; - dm = kmalloc(sizeof(*dm), GFP_KERNEL); + dm = kmalloc_obj(*dm, GFP_KERNEL); if (!dm) return -ENOMEM; dm->ino = ino; @@ -3352,7 +3352,7 @@ static int add_pending_dir_move(struct send_ctx *sctx, int exists = 0; int ret; - pm = kmalloc(sizeof(*pm), GFP_KERNEL); + pm = kmalloc_obj(*pm, GFP_KERNEL); if (!pm) return -ENOMEM; pm->parent_ino = parent_ino; @@ -8035,7 +8035,7 @@ long btrfs_ioctl_send(struct btrfs_root *send_root, const struct btrfs_ioctl_sen goto out; } - sctx = kzalloc(sizeof(struct send_ctx), GFP_KERNEL); + sctx = kzalloc_obj(struct send_ctx, GFP_KERNEL); if (!sctx) { ret = -ENOMEM; goto out; @@ -8097,9 +8097,9 @@ long btrfs_ioctl_send(struct btrfs_root *send_root, const struct btrfs_ioctl_sen goto out; } send_buf_num_pages = sctx->send_max_size >> PAGE_SHIFT; - sctx->send_buf_pages = kcalloc(send_buf_num_pages, - sizeof(*sctx->send_buf_pages), - GFP_KERNEL); + sctx->send_buf_pages = kzalloc_objs(*sctx->send_buf_pages, + send_buf_num_pages, + GFP_KERNEL); if (!sctx->send_buf_pages) { ret = -ENOMEM; goto out; @@ -8117,9 +8117,9 @@ long btrfs_ioctl_send(struct btrfs_root *send_root, const struct btrfs_ioctl_sen goto out; } - sctx->clone_roots = kvcalloc(arg->clone_sources_count + 1, - sizeof(*sctx->clone_roots), - GFP_KERNEL); + sctx->clone_roots = kvzalloc_objs(*sctx->clone_roots, + arg->clone_sources_count + 1, + GFP_KERNEL); if (!sctx->clone_roots) { ret = -ENOMEM; goto out; diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index bb5aac7ee9d2..52a267a5dd80 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -266,7 +266,7 @@ static int create_space_info_sub_group(struct btrfs_space_info *parent, u64 flag "parent->subgroup_id=%d", parent->subgroup_id); ASSERT(id != BTRFS_SUB_GROUP_PRIMARY, "id=%d", id); - sub_group = kzalloc(sizeof(*sub_group), GFP_NOFS); + sub_group = kzalloc_obj(*sub_group, GFP_NOFS); if (!sub_group) return -ENOMEM; @@ -289,7 +289,7 @@ static int create_space_info(struct btrfs_fs_info *info, u64 flags) struct btrfs_space_info *space_info; int ret = 0; - space_info = kzalloc(sizeof(*space_info), GFP_NOFS); + space_info = kzalloc_obj(*space_info, GFP_NOFS); if (!space_info) return -ENOMEM; diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index d64d303b6edc..3f9523563259 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -2054,7 +2054,7 @@ static int btrfs_get_tree_subvol(struct fs_context *fc) * of the fs_info (locks and such) to make cleanup easier if we find a * superblock with our given fs_devices later on at sget() time. */ - fs_info = kvzalloc(sizeof(struct btrfs_fs_info), GFP_KERNEL); + fs_info = kvzalloc_obj(struct btrfs_fs_info, GFP_KERNEL); if (!fs_info) return -ENOMEM; @@ -2173,7 +2173,7 @@ static int btrfs_init_fs_context(struct fs_context *fc) { struct btrfs_fs_context *ctx; - ctx = kzalloc(sizeof(struct btrfs_fs_context), GFP_KERNEL); + ctx = kzalloc_obj(struct btrfs_fs_context, GFP_KERNEL); if (!ctx) return -ENOMEM; diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 27bfb7b55ec4..f62278f0c191 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -1833,7 +1833,7 @@ void btrfs_sysfs_add_block_group_type(struct btrfs_block_group *cache) */ nofs_flag = memalloc_nofs_save(); - rkobj = kzalloc(sizeof(*rkobj), GFP_NOFS); + rkobj = kzalloc_obj(*rkobj, GFP_NOFS); if (!rkobj) { memalloc_nofs_restore(nofs_flag); btrfs_warn(cache->fs_info, @@ -2597,7 +2597,7 @@ int btrfs_sysfs_add_qgroups(struct btrfs_fs_info *fs_info) if (fs_info->qgroups_kobj) return 0; - fs_info->qgroups_kobj = kzalloc(sizeof(struct kobject), GFP_KERNEL); + fs_info->qgroups_kobj = kzalloc_obj(struct kobject, GFP_KERNEL); if (!fs_info->qgroups_kobj) return -ENOMEM; diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c index 7f13c05d3736..c5b1bc0f7f91 100644 --- a/fs/btrfs/tests/btrfs-tests.c +++ b/fs/btrfs/tests/btrfs-tests.c @@ -98,7 +98,7 @@ struct btrfs_device *btrfs_alloc_dummy_device(struct btrfs_fs_info *fs_info) { struct btrfs_device *dev; - dev = kzalloc(sizeof(*dev), GFP_KERNEL); + dev = kzalloc_obj(*dev, GFP_KERNEL); if (!dev) return ERR_PTR(-ENOMEM); @@ -117,21 +117,19 @@ static void btrfs_free_dummy_device(struct btrfs_device *dev) struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(u32 nodesize, u32 sectorsize) { - struct btrfs_fs_info *fs_info = kzalloc(sizeof(struct btrfs_fs_info), - GFP_KERNEL); + struct btrfs_fs_info *fs_info = kzalloc_obj(struct btrfs_fs_info, + GFP_KERNEL); if (!fs_info) return fs_info; - fs_info->fs_devices = kzalloc(sizeof(struct btrfs_fs_devices), - GFP_KERNEL); + fs_info->fs_devices = kzalloc_obj(struct btrfs_fs_devices, GFP_KERNEL); if (!fs_info->fs_devices) { kfree(fs_info); return NULL; } INIT_LIST_HEAD(&fs_info->fs_devices->devices); - fs_info->super_copy = kzalloc(sizeof(struct btrfs_super_block), - GFP_KERNEL); + fs_info->super_copy = kzalloc_obj(struct btrfs_super_block, GFP_KERNEL); if (!fs_info->super_copy) { kfree(fs_info->fs_devices); kfree(fs_info); @@ -208,11 +206,10 @@ btrfs_alloc_dummy_block_group(struct btrfs_fs_info *fs_info, { struct btrfs_block_group *cache; - cache = kzalloc(sizeof(*cache), GFP_KERNEL); + cache = kzalloc_obj(*cache, GFP_KERNEL); if (!cache) return NULL; - cache->free_space_ctl = kzalloc(sizeof(*cache->free_space_ctl), - GFP_KERNEL); + cache->free_space_ctl = kzalloc_obj(*cache->free_space_ctl, GFP_KERNEL); if (!cache->free_space_ctl) { kfree(cache); return NULL; diff --git a/fs/btrfs/tests/delayed-refs-tests.c b/fs/btrfs/tests/delayed-refs-tests.c index e2248acb906b..fdc183ebc6da 100644 --- a/fs/btrfs/tests/delayed-refs-tests.c +++ b/fs/btrfs/tests/delayed-refs-tests.c @@ -985,7 +985,7 @@ int btrfs_test_delayed_refs(u32 sectorsize, u32 nodesize) test_std_err(TEST_ALLOC_FS_INFO); return -ENOMEM; } - transaction = kmalloc(sizeof(*transaction), GFP_KERNEL); + transaction = kmalloc_obj(*transaction, GFP_KERNEL); if (!transaction) { test_std_err(TEST_ALLOC_TRANSACTION); ret = -ENOMEM; diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 463238ca8a4d..7ef8c9b7dfc1 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -315,7 +315,7 @@ loop: */ BUG_ON(type == TRANS_JOIN_NOLOCK); - cur_trans = kmalloc(sizeof(*cur_trans), GFP_NOFS); + cur_trans = kmalloc_obj(*cur_trans, GFP_NOFS); if (!cur_trans) return -ENOMEM; diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index e1bd03ebfd98..780a06d59240 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -5928,7 +5928,7 @@ again: if (ret) goto out; if (ctx->log_new_dentries) { - dir_elem = kmalloc(sizeof(*dir_elem), GFP_NOFS); + dir_elem = kmalloc_obj(*dir_elem, GFP_NOFS); if (!dir_elem) { ret = -ENOMEM; goto out; @@ -6122,7 +6122,7 @@ static int add_conflicting_inode(struct btrfs_trans_handle *trans, return ret; /* Conflicting inode is a directory, so we'll log its parent. */ - ino_elem = kmalloc(sizeof(*ino_elem), GFP_NOFS); + ino_elem = kmalloc_obj(*ino_elem, GFP_NOFS); if (!ino_elem) return -ENOMEM; ino_elem->ino = ino; @@ -6180,7 +6180,7 @@ static int add_conflicting_inode(struct btrfs_trans_handle *trans, btrfs_add_delayed_iput(inode); - ino_elem = kmalloc(sizeof(*ino_elem), GFP_NOFS); + ino_elem = kmalloc_obj(*ino_elem, GFP_NOFS); if (!ino_elem) return -ENOMEM; ino_elem->ino = ino; diff --git a/fs/btrfs/tree-mod-log.c b/fs/btrfs/tree-mod-log.c index 9e8cb3b7c064..603c1457130e 100644 --- a/fs/btrfs/tree-mod-log.c +++ b/fs/btrfs/tree-mod-log.c @@ -243,7 +243,7 @@ static struct tree_mod_elem *alloc_tree_mod_elem(const struct extent_buffer *eb, ASSERT(op != BTRFS_MOD_LOG_MOVE_KEYS); ASSERT(op != BTRFS_MOD_LOG_ROOT_REPLACE); - tm = kzalloc(sizeof(*tm), GFP_NOFS); + tm = kzalloc_obj(*tm, GFP_NOFS); if (!tm) return NULL; @@ -301,7 +301,7 @@ static struct tree_mod_elem *tree_mod_log_alloc_move(const struct extent_buffer { struct tree_mod_elem *tm; - tm = kzalloc(sizeof(*tm), GFP_NOFS); + tm = kzalloc_obj(*tm, GFP_NOFS); if (!tm) return ERR_PTR(-ENOMEM); @@ -328,7 +328,7 @@ int btrfs_tree_mod_log_insert_move(const struct extent_buffer *eb, if (!tree_mod_need_log(eb->fs_info, eb)) return 0; - tm_list = kcalloc(nr_items, sizeof(struct tree_mod_elem *), GFP_NOFS); + tm_list = kzalloc_objs(struct tree_mod_elem *, nr_items, GFP_NOFS); if (!tm_list) { ret = -ENOMEM; goto lock; @@ -439,8 +439,8 @@ int btrfs_tree_mod_log_insert_root(struct extent_buffer *old_root, if (log_removal && btrfs_header_level(old_root) > 0) { nritems = btrfs_header_nritems(old_root); - tm_list = kcalloc(nritems, sizeof(struct tree_mod_elem *), - GFP_NOFS); + tm_list = kzalloc_objs(struct tree_mod_elem *, nritems, + GFP_NOFS); if (!tm_list) { ret = -ENOMEM; goto lock; @@ -455,7 +455,7 @@ int btrfs_tree_mod_log_insert_root(struct extent_buffer *old_root, } } - tm = kzalloc(sizeof(*tm), GFP_NOFS); + tm = kzalloc_obj(*tm, GFP_NOFS); if (!tm) { ret = -ENOMEM; goto lock; @@ -595,8 +595,7 @@ int btrfs_tree_mod_log_eb_copy(struct extent_buffer *dst, if (btrfs_header_level(dst) == 0 && btrfs_header_level(src) == 0) return 0; - tm_list = kcalloc(nr_items * 2, sizeof(struct tree_mod_elem *), - GFP_NOFS); + tm_list = kzalloc_objs(struct tree_mod_elem *, nr_items * 2, GFP_NOFS); if (!tm_list) { ret = -ENOMEM; goto lock; @@ -714,7 +713,7 @@ int btrfs_tree_mod_log_free_eb(struct extent_buffer *eb) return 0; nritems = btrfs_header_nritems(eb); - tm_list = kcalloc(nritems, sizeof(struct tree_mod_elem *), GFP_NOFS); + tm_list = kzalloc_objs(struct tree_mod_elem *, nritems, GFP_NOFS); if (!tm_list) { ret = -ENOMEM; goto lock; diff --git a/fs/btrfs/ulist.c b/fs/btrfs/ulist.c index 7e16a253fb35..7898076ce41c 100644 --- a/fs/btrfs/ulist.c +++ b/fs/btrfs/ulist.c @@ -98,7 +98,7 @@ void ulist_reinit(struct ulist *ulist) */ struct ulist *ulist_alloc(gfp_t gfp_mask) { - struct ulist *ulist = kmalloc(sizeof(*ulist), gfp_mask); + struct ulist *ulist = kmalloc_obj(*ulist, gfp_mask); if (!ulist) return NULL; @@ -111,7 +111,7 @@ struct ulist *ulist_alloc(gfp_t gfp_mask) void ulist_prealloc(struct ulist *ulist, gfp_t gfp_mask) { if (!ulist->prealloc) - ulist->prealloc = kzalloc(sizeof(*ulist->prealloc), gfp_mask); + ulist->prealloc = kzalloc_obj(*ulist->prealloc, gfp_mask); } /* @@ -219,7 +219,7 @@ int ulist_add_merge(struct ulist *ulist, u64 val, u64 aux, node = ulist->prealloc; ulist->prealloc = NULL; } else { - node = kmalloc(sizeof(*node), gfp_mask); + node = kmalloc_obj(*node, gfp_mask); if (!node) return -ENOMEM; } diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 50f7aae70418..71ff7006ca6b 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -382,7 +382,7 @@ static struct btrfs_fs_devices *alloc_fs_devices(const u8 *fsid) { struct btrfs_fs_devices *fs_devs; - fs_devs = kzalloc(sizeof(*fs_devs), GFP_KERNEL); + fs_devs = kzalloc_obj(*fs_devs, GFP_KERNEL); if (!fs_devs) return ERR_PTR(-ENOMEM); @@ -4456,7 +4456,7 @@ again: if (chunk_type & BTRFS_BLOCK_GROUP_METADATA_REMAP) { mutex_unlock(&fs_info->reclaim_bgs_lock); - rci = kmalloc(sizeof(struct remap_chunk_info), GFP_NOFS); + rci = kmalloc_obj(struct remap_chunk_info, GFP_NOFS); if (!rci) { ret = -ENOMEM; goto error; @@ -5004,7 +5004,7 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info) return 0; } - bctl = kzalloc(sizeof(*bctl), GFP_NOFS); + bctl = kzalloc_obj(*bctl, GFP_NOFS); if (!bctl) return -ENOMEM; @@ -6338,7 +6338,7 @@ struct btrfs_io_context *alloc_btrfs_io_context(struct btrfs_fs_info *fs_info, { struct btrfs_io_context *bioc; - bioc = kzalloc(struct_size(bioc, stripes, total_stripes), GFP_NOFS); + bioc = kzalloc_flex(*bioc, stripes, total_stripes, GFP_NOFS); if (!bioc) return NULL; @@ -6471,7 +6471,7 @@ struct btrfs_discard_stripe *btrfs_map_discard(struct btrfs_fs_info *fs_info, stripe_nr /= map->num_stripes; } - stripes = kcalloc(*num_stripes, sizeof(*stripes), GFP_NOFS); + stripes = kzalloc_objs(*stripes, *num_stripes, GFP_NOFS); if (!stripes) { ret = -ENOMEM; goto out_free_map; @@ -7202,7 +7202,7 @@ struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info, if (WARN_ON(!devid && !fs_info)) return ERR_PTR(-EINVAL); - dev = kzalloc(sizeof(*dev), GFP_KERNEL); + dev = kzalloc_obj(*dev, GFP_KERNEL); if (!dev) return ERR_PTR(-ENOMEM); diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index 0a8fcee16428..5a0913a31991 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -75,7 +75,7 @@ struct list_head *zlib_alloc_workspace(struct btrfs_fs_info *fs_info, unsigned i struct workspace *workspace; int workspacesize; - workspace = kzalloc(sizeof(*workspace), GFP_KERNEL); + workspace = kzalloc_obj(*workspace, GFP_KERNEL); if (!workspace) return ERR_PTR(-ENOMEM); diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index ad8621587fd2..fcdfb831b484 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -377,7 +377,7 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache) if (device->zone_info) return 0; - zone_info = kzalloc(sizeof(*zone_info), GFP_KERNEL); + zone_info = kzalloc_obj(*zone_info, GFP_KERNEL); if (!zone_info) return -ENOMEM; @@ -454,7 +454,8 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache) goto out; } - zones = kvcalloc(BTRFS_REPORT_NR_ZONES, sizeof(struct blk_zone), GFP_KERNEL); + zones = kvzalloc_objs(struct blk_zone, BTRFS_REPORT_NR_ZONES, + GFP_KERNEL); if (!zones) { ret = -ENOMEM; goto out; diff --git a/fs/btrfs/zstd.c b/fs/btrfs/zstd.c index 32fd7f5454d3..a7a41dd320d9 100644 --- a/fs/btrfs/zstd.c +++ b/fs/btrfs/zstd.c @@ -185,7 +185,7 @@ int zstd_alloc_workspace_manager(struct btrfs_fs_info *fs_info) struct list_head *ws; ASSERT(fs_info->compr_wsm[BTRFS_COMPRESS_ZSTD] == NULL); - zwsm = kzalloc(sizeof(*zwsm), GFP_KERNEL); + zwsm = kzalloc_obj(*zwsm, GFP_KERNEL); if (!zwsm) return -ENOMEM; zstd_calc_ws_mem_sizes(); @@ -373,7 +373,7 @@ struct list_head *zstd_alloc_workspace(struct btrfs_fs_info *fs_info, int level) const u32 blocksize = fs_info->sectorsize; struct workspace *workspace; - workspace = kzalloc(sizeof(*workspace), GFP_KERNEL); + workspace = kzalloc_obj(*workspace, GFP_KERNEL); if (!workspace) return ERR_PTR(-ENOMEM); |
