mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
This is the result of running the Coccinelle script from scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to avoid scalar types (which need careful case-by-case checking), and instead replace kmalloc-family calls that allocate struct or union object instances: Single allocations: kmalloc(sizeof(TYPE), ...) are replaced with: kmalloc_obj(TYPE, ...) Array allocations: kmalloc_array(COUNT, sizeof(TYPE), ...) are replaced with: kmalloc_objs(TYPE, COUNT, ...) Flex array allocations: kmalloc(struct_size(PTR, FAM, COUNT), ...) are replaced with: kmalloc_flex(*PTR, FAM, COUNT, ...) (where TYPE may also be *VAR) The resulting allocations no longer return "void *", instead returning "TYPE *". Signed-off-by: Kees Cook <kees@kernel.org>
This commit is contained in:
@@ -152,7 +152,7 @@ static void * r10buf_pool_alloc(gfp_t gfp_flags, void *data)
|
||||
nalloc_rp = nalloc;
|
||||
else
|
||||
nalloc_rp = nalloc * 2;
|
||||
rps = kmalloc_array(nalloc_rp, sizeof(struct resync_pages), gfp_flags);
|
||||
rps = kmalloc_objs(struct resync_pages, nalloc_rp, gfp_flags);
|
||||
if (!rps)
|
||||
goto out_free_r10bio;
|
||||
|
||||
@@ -3852,14 +3852,14 @@ static struct r10conf *setup_conf(struct mddev *mddev)
|
||||
}
|
||||
|
||||
err = -ENOMEM;
|
||||
conf = kzalloc(sizeof(struct r10conf), GFP_KERNEL);
|
||||
conf = kzalloc_obj(struct r10conf, GFP_KERNEL);
|
||||
if (!conf)
|
||||
goto out;
|
||||
|
||||
/* FIXME calc properly */
|
||||
conf->mirrors = kcalloc(mddev->raid_disks + max(0, -mddev->delta_disks),
|
||||
sizeof(struct raid10_info),
|
||||
GFP_KERNEL);
|
||||
conf->mirrors = kzalloc_objs(struct raid10_info,
|
||||
mddev->raid_disks + max(0, -mddev->delta_disks),
|
||||
GFP_KERNEL);
|
||||
if (!conf->mirrors)
|
||||
goto out;
|
||||
|
||||
@@ -4281,9 +4281,9 @@ static int raid10_check_reshape(struct mddev *mddev)
|
||||
if (mddev->delta_disks > 0) {
|
||||
/* allocate new 'mirrors' list */
|
||||
conf->mirrors_new =
|
||||
kcalloc(mddev->raid_disks + mddev->delta_disks,
|
||||
sizeof(struct raid10_info),
|
||||
GFP_KERNEL);
|
||||
kzalloc_objs(struct raid10_info,
|
||||
mddev->raid_disks + mddev->delta_disks,
|
||||
GFP_KERNEL);
|
||||
if (!conf->mirrors_new)
|
||||
return -ENOMEM;
|
||||
}
|
||||
@@ -4918,7 +4918,7 @@ static int handle_reshape_read_error(struct mddev *mddev,
|
||||
int idx = 0;
|
||||
struct page **pages;
|
||||
|
||||
r10b = kmalloc(struct_size(r10b, devs, conf->copies), GFP_NOIO);
|
||||
r10b = kmalloc_flex(*r10b, devs, conf->copies, GFP_NOIO);
|
||||
if (!r10b) {
|
||||
set_bit(MD_RECOVERY_INTR, &mddev->recovery);
|
||||
return -ENOMEM;
|
||||
|
||||
Reference in New Issue
Block a user