From: Miquel Sabaté Solà Date: Tue, 24 Feb 2026 21:45:44 +0000 (+0100) Subject: btrfs: replace kcalloc() calls to kzalloc_objs() X-Git-Tag: v7.1-rc1~231^2~68 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=2d2b5507e598984f5832f0c5193f35733c42995e;p=thirdparty%2Fkernel%2Flinux.git btrfs: replace kcalloc() calls to kzalloc_objs() Commit 2932ba8d9c99 ("slab: Introduce kmalloc_obj() and family") introduced, among many others, the kzalloc_objs() helper, which has some benefits over kcalloc(). Namely, internal introspection of the allocated type now becomes possible, allowing for future alignment-aware choices to be made by the allocator and future hardening work that can be type sensitive. Dropping 'sizeof' comes also as a nice side-effect. Moreover, this also allows us to be in line with the recent tree-wide migration to the kmalloc_obj() and family of helpers. See commit 69050f8d6d07 ("treewide: Replace kmalloc with kmalloc_obj for non-scalar types"). Reviewed-by: Kees Cook Signed-off-by: Miquel Sabaté Solà Reviewed-by: David Sterba Signed-off-by: David Sterba --- diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index d21df4446e3d8..b5c2747158092 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -2239,7 +2239,7 @@ int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start, if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) io_stripe_size = btrfs_stripe_nr_to_offset(nr_data_stripes(map)); - buf = kcalloc(map->num_stripes, sizeof(u64), GFP_NOFS); + buf = kzalloc_objs(u64, map->num_stripes, GFP_NOFS); if (!buf) { ret = -ENOMEM; goto out; diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c index aacf5e4eb765c..e31d57d6ab1e7 100644 --- a/fs/btrfs/raid56.c +++ b/fs/btrfs/raid56.c @@ -2105,8 +2105,8 @@ static int recover_sectors(struct btrfs_raid_bio *rbio) * @unmap_array stores copy of pointers that does not get reordered * during reconstruction so that kunmap_local works. */ - pointers = kcalloc(rbio->real_stripes, sizeof(void *), GFP_NOFS); - unmap_array = kcalloc(rbio->real_stripes, sizeof(void *), GFP_NOFS); + pointers = kzalloc_objs(void *, rbio->real_stripes, GFP_NOFS); + unmap_array = kzalloc_objs(void *, rbio->real_stripes, GFP_NOFS); if (!pointers || !unmap_array) { ret = -ENOMEM; goto out; @@ -2839,8 +2839,8 @@ static int recover_scrub_rbio(struct btrfs_raid_bio *rbio) * @unmap_array stores copy of pointers that does not get reordered * during reconstruction so that kunmap_local works. */ - pointers = kcalloc(rbio->real_stripes, sizeof(void *), GFP_NOFS); - unmap_array = kcalloc(rbio->real_stripes, sizeof(void *), GFP_NOFS); + pointers = kzalloc_objs(void *, rbio->real_stripes, GFP_NOFS); + unmap_array = kzalloc_objs(void *, rbio->real_stripes, GFP_NOFS); if (!pointers || !unmap_array) { ret = -ENOMEM; goto out; diff --git a/fs/btrfs/tests/zoned-tests.c b/fs/btrfs/tests/zoned-tests.c index da21c7aea31af..2bc3b14baa410 100644 --- a/fs/btrfs/tests/zoned-tests.c +++ b/fs/btrfs/tests/zoned-tests.c @@ -58,7 +58,7 @@ static int test_load_zone_info(struct btrfs_fs_info *fs_info, return -ENOMEM; } - zone_info = kcalloc(test->num_stripes, sizeof(*zone_info), GFP_KERNEL); + zone_info = kzalloc_objs(*zone_info, test->num_stripes, GFP_KERNEL); if (!zone_info) { test_err("cannot allocate zone info"); return -ENOMEM; diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 62e02cc1efc93..deaf1997a3a59 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5508,8 +5508,7 @@ static int calc_one_profile_avail(struct btrfs_fs_info *fs_info, goto out; } - devices_info = kcalloc(fs_devices->rw_devices, sizeof(*devices_info), - GFP_NOFS); + devices_info = kzalloc_objs(*devices_info, fs_devices->rw_devices, GFP_NOFS); if (!devices_info) { ret = -ENOMEM; goto out; @@ -6076,8 +6075,7 @@ struct btrfs_block_group *btrfs_create_chunk(struct btrfs_trans_handle *trans, ctl.space_info = space_info; init_alloc_chunk_ctl(fs_devices, &ctl); - devices_info = kcalloc(fs_devices->rw_devices, sizeof(*devices_info), - GFP_NOFS); + devices_info = kzalloc_objs(*devices_info, fs_devices->rw_devices, GFP_NOFS); if (!devices_info) return ERR_PTR(-ENOMEM); diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 11f4bdd617bb3..f7ca01a32a031 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1699,8 +1699,7 @@ static int btrfs_load_block_group_raid10(struct btrfs_block_group *bg, return -EINVAL; } - raid0_allocs = kcalloc(map->num_stripes / map->sub_stripes, sizeof(*raid0_allocs), - GFP_NOFS); + raid0_allocs = kzalloc_objs(*raid0_allocs, map->num_stripes / map->sub_stripes, GFP_NOFS); if (!raid0_allocs) return -ENOMEM; @@ -1918,7 +1917,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) cache->physical_map = map; - zone_info = kcalloc(map->num_stripes, sizeof(*zone_info), GFP_NOFS); + zone_info = kzalloc_objs(*zone_info, map->num_stripes, GFP_NOFS); if (!zone_info) { ret = -ENOMEM; goto out;