mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 23:03:57 -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:
@@ -397,7 +397,7 @@ static int zcdn_create(const char *name)
|
||||
}
|
||||
|
||||
/* alloc and prepare a new zcdn device */
|
||||
zcdndev = kzalloc(sizeof(*zcdndev), GFP_KERNEL);
|
||||
zcdndev = kzalloc_obj(*zcdndev, GFP_KERNEL);
|
||||
if (!zcdndev) {
|
||||
rc = -ENOMEM;
|
||||
goto unlockout;
|
||||
@@ -1065,7 +1065,7 @@ static long _zcrypt_send_ep11_cprb(u32 xflags, struct ap_perms *perms,
|
||||
rc = -ENOMEM;
|
||||
if (target_num != 0) {
|
||||
if (userspace) {
|
||||
targets = kcalloc(target_num, sizeof(*targets), GFP_KERNEL);
|
||||
targets = kzalloc_objs(*targets, target_num, GFP_KERNEL);
|
||||
if (!targets)
|
||||
goto out;
|
||||
if (copy_from_user(targets, xcrb->targets,
|
||||
@@ -1627,9 +1627,8 @@ static long zcrypt_unlocked_ioctl(struct file *filp, unsigned int cmd,
|
||||
size_t total_size = MAX_ZDEV_ENTRIES_EXT
|
||||
* sizeof(struct zcrypt_device_status_ext);
|
||||
|
||||
device_status = kvcalloc(MAX_ZDEV_ENTRIES_EXT,
|
||||
sizeof(struct zcrypt_device_status_ext),
|
||||
GFP_KERNEL);
|
||||
device_status = kvzalloc_objs(struct zcrypt_device_status_ext,
|
||||
MAX_ZDEV_ENTRIES_EXT, GFP_KERNEL);
|
||||
if (!device_status)
|
||||
return -ENOMEM;
|
||||
zcrypt_device_status_mask_ext(device_status,
|
||||
|
||||
Reference in New Issue
Block a user