diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-02-24 22:45:44 +0100 |
|---|---|---|
| committer | David Sterba <dsterba@suse.com> | 2026-04-07 18:55:59 +0200 |
| commit | 2d2b5507e598984f5832f0c5193f35733c42995e (patch) | |
| tree | c322c7f39254bd87a8a220cf5db89b74191ad893 | |
| parent | 6603a9859887ed325fea9fc9347c2d9e6cf3bbe3 (diff) | |
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 <kees@kernel.org>
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
| -rw-r--r-- | fs/btrfs/block-group.c | 2 | ||||
| -rw-r--r-- | fs/btrfs/raid56.c | 8 | ||||
| -rw-r--r-- | fs/btrfs/tests/zoned-tests.c | 2 | ||||
| -rw-r--r-- | fs/btrfs/volumes.c | 6 | ||||
| -rw-r--r-- | fs/btrfs/zoned.c | 5 |
5 files changed, 10 insertions, 13 deletions
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index d21df4446e3d..b5c274715809 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 aacf5e4eb765..e31d57d6ab1e 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 da21c7aea31a..2bc3b14baa41 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 62e02cc1efc9..deaf1997a3a5 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 11f4bdd617bb..f7ca01a32a03 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; |
