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:
Kees Cook
2026-02-20 23:49:23 -08:00
parent d39a1d7486
commit 69050f8d6d
8016 changed files with 20055 additions and 20913 deletions

View File

@@ -1536,7 +1536,7 @@ int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info)
goto out;
}
new_disk_conf = kmalloc(sizeof(struct disk_conf), GFP_KERNEL);
new_disk_conf = kmalloc_obj(struct disk_conf, GFP_KERNEL);
if (!new_disk_conf) {
retcode = ERR_NOMEM;
goto fail;
@@ -1785,14 +1785,14 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info)
atomic_set(&device->rs_pending_cnt, 0);
/* allocation not in the IO path, drbdsetup context */
nbc = kzalloc(sizeof(struct drbd_backing_dev), GFP_KERNEL);
nbc = kzalloc_obj(struct drbd_backing_dev, GFP_KERNEL);
if (!nbc) {
retcode = ERR_NOMEM;
goto fail;
}
spin_lock_init(&nbc->md.uuid_lock);
new_disk_conf = kzalloc(sizeof(struct disk_conf), GFP_KERNEL);
new_disk_conf = kzalloc_obj(struct disk_conf, GFP_KERNEL);
if (!new_disk_conf) {
retcode = ERR_NOMEM;
goto fail;
@@ -2390,7 +2390,7 @@ int drbd_adm_net_opts(struct sk_buff *skb, struct genl_info *info)
connection = adm_ctx.connection;
mutex_lock(&adm_ctx.resource->adm_mutex);
new_net_conf = kzalloc(sizeof(struct net_conf), GFP_KERNEL);
new_net_conf = kzalloc_obj(struct net_conf, GFP_KERNEL);
if (!new_net_conf) {
retcode = ERR_NOMEM;
goto out;
@@ -2570,7 +2570,7 @@ int drbd_adm_connect(struct sk_buff *skb, struct genl_info *info)
}
/* allocation not in the IO path, drbdsetup / netlink process context */
new_net_conf = kzalloc(sizeof(*new_net_conf), GFP_KERNEL);
new_net_conf = kzalloc_obj(*new_net_conf, GFP_KERNEL);
if (!new_net_conf) {
retcode = ERR_NOMEM;
goto fail;
@@ -2840,7 +2840,7 @@ int drbd_adm_resize(struct sk_buff *skb, struct genl_info *info)
u_size = rcu_dereference(device->ldev->disk_conf)->disk_size;
rcu_read_unlock();
if (u_size != (sector_t)rs.resize_size) {
new_disk_conf = kmalloc(sizeof(struct disk_conf), GFP_KERNEL);
new_disk_conf = kmalloc_obj(struct disk_conf, GFP_KERNEL);
if (!new_disk_conf) {
retcode = ERR_NOMEM;
goto fail_ldev;