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

@@ -922,7 +922,7 @@ static struct rpmsg_endpoint *qcom_smd_create_ept(struct rpmsg_device *rpdev,
return NULL;
}
qsept = kzalloc(sizeof(*qsept), GFP_KERNEL);
qsept = kzalloc_obj(*qsept, GFP_KERNEL);
if (!qsept)
return NULL;
@@ -1077,7 +1077,7 @@ static int qcom_smd_create_device(struct qcom_smd_channel *channel)
dev_dbg(&edge->dev, "registering '%s'\n", channel->name);
qsdev = kzalloc(sizeof(*qsdev), GFP_KERNEL);
qsdev = kzalloc_obj(*qsdev, GFP_KERNEL);
if (!qsdev)
return -ENOMEM;
@@ -1104,7 +1104,7 @@ static int qcom_smd_create_chrdev(struct qcom_smd_edge *edge)
{
struct qcom_smd_device *qsdev;
qsdev = kzalloc(sizeof(*qsdev), GFP_KERNEL);
qsdev = kzalloc_obj(*qsdev, GFP_KERNEL);
if (!qsdev)
return -ENOMEM;
@@ -1132,7 +1132,7 @@ static struct qcom_smd_channel *qcom_smd_create_channel(struct qcom_smd_edge *ed
void *info;
int ret;
channel = kzalloc(sizeof(*channel), GFP_KERNEL);
channel = kzalloc_obj(*channel, GFP_KERNEL);
if (!channel)
return ERR_PTR(-ENOMEM);
@@ -1484,7 +1484,7 @@ struct qcom_smd_edge *qcom_smd_register_edge(struct device *parent,
if (!qcom_smem_is_available())
return ERR_PTR(-EPROBE_DEFER);
edge = kzalloc(sizeof(*edge), GFP_KERNEL);
edge = kzalloc_obj(*edge, GFP_KERNEL);
if (!edge)
return ERR_PTR(-ENOMEM);