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:
@@ -410,7 +410,7 @@ ffa_partition_probe(const uuid_t *uuid, struct ffa_partition_info **buffer)
|
||||
if (count <= 0)
|
||||
return count;
|
||||
|
||||
pbuf = kcalloc(count, sizeof(*pbuf), GFP_KERNEL);
|
||||
pbuf = kzalloc_objs(*pbuf, count, GFP_KERNEL);
|
||||
if (!pbuf)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -1376,7 +1376,7 @@ static int __ffa_notify_request(struct ffa_device *dev, bool is_per_vcpu,
|
||||
if (notify_id >= FFA_MAX_NOTIFICATIONS)
|
||||
return -EINVAL;
|
||||
|
||||
cb_info = kzalloc(sizeof(*cb_info), GFP_KERNEL);
|
||||
cb_info = kzalloc_obj(*cb_info, GFP_KERNEL);
|
||||
if (!cb_info)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -1647,7 +1647,7 @@ static int ffa_xa_add_partition_info(struct ffa_device *dev)
|
||||
}
|
||||
}
|
||||
|
||||
info = kzalloc(sizeof(*info), GFP_KERNEL);
|
||||
info = kzalloc_obj(*info, GFP_KERNEL);
|
||||
if (!info)
|
||||
return ret;
|
||||
|
||||
@@ -1655,7 +1655,7 @@ static int ffa_xa_add_partition_info(struct ffa_device *dev)
|
||||
info->dev = dev;
|
||||
|
||||
if (!phead) {
|
||||
phead = kzalloc(sizeof(*phead), GFP_KERNEL);
|
||||
phead = kzalloc_obj(*phead, GFP_KERNEL);
|
||||
if (!phead)
|
||||
goto free_out;
|
||||
|
||||
@@ -2039,7 +2039,7 @@ static int __init ffa_init(void)
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
drv_info = kzalloc(sizeof(*drv_info), GFP_KERNEL);
|
||||
drv_info = kzalloc_obj(*drv_info, GFP_KERNEL);
|
||||
if (!drv_info)
|
||||
return -ENOMEM;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user