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>
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;
* @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;
* @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;
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;
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;
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);
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;
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;