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

@@ -324,7 +324,7 @@ static struct rnbd_iu *rnbd_get_iu(struct rnbd_clt_session *sess,
struct rnbd_iu *iu;
struct rtrs_permit *permit;
iu = kzalloc(sizeof(*iu), GFP_KERNEL);
iu = kzalloc_obj(*iu, GFP_KERNEL);
if (!iu)
return NULL;
@@ -541,7 +541,7 @@ static int send_msg_open(struct rnbd_clt_dev *dev, enum wait_type wait)
};
int err, errno;
rsp = kzalloc(sizeof(*rsp), GFP_KERNEL);
rsp = kzalloc_obj(*rsp, GFP_KERNEL);
if (!rsp)
return -ENOMEM;
@@ -587,7 +587,7 @@ static int send_msg_sess_info(struct rnbd_clt_session *sess, enum wait_type wait
};
int err, errno;
rsp = kzalloc(sizeof(*rsp), GFP_KERNEL);
rsp = kzalloc_obj(*rsp, GFP_KERNEL);
if (!rsp)
return -ENOMEM;
@@ -1417,9 +1417,8 @@ static struct rnbd_clt_dev *init_dev(struct rnbd_clt_session *sess,
* nr_cpu_ids: the number of softirq queues
* nr_poll_queues: the number of polling queues
*/
dev->hw_queues = kcalloc(nr_cpu_ids + nr_poll_queues,
sizeof(*dev->hw_queues),
GFP_KERNEL);
dev->hw_queues = kzalloc_objs(*dev->hw_queues,
nr_cpu_ids + nr_poll_queues, GFP_KERNEL);
if (!dev->hw_queues) {
ret = -ENOMEM;
goto out_alloc;
@@ -1565,7 +1564,7 @@ struct rnbd_clt_dev *rnbd_clt_map_device(const char *sessname,
goto put_dev;
}
rsp = kzalloc(sizeof(*rsp), GFP_KERNEL);
rsp = kzalloc_obj(*rsp, GFP_KERNEL);
if (!rsp) {
ret = -ENOMEM;
goto del_dev;