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

@@ -54,7 +54,7 @@ exynos_srom_alloc_reg_dump(const unsigned long *rdump,
struct exynos_srom_reg_dump *rd;
unsigned int i;
rd = kcalloc(nr_rdump, sizeof(*rd), GFP_KERNEL);
rd = kzalloc_objs(*rd, nr_rdump, GFP_KERNEL);
if (!rd)
return NULL;

View File

@@ -1291,7 +1291,7 @@ emc_of_icc_xlate_extended(const struct of_phandle_args *spec, void *data)
if (node->id != TEGRA_ICC_EMEM)
continue;
ndata = kzalloc(sizeof(*ndata), GFP_KERNEL);
ndata = kzalloc_obj(*ndata, GFP_KERNEL);
if (!ndata)
return ERR_PTR(-ENOMEM);

View File

@@ -1182,7 +1182,7 @@ tegra124_mc_of_icc_xlate_extended(const struct of_phandle_args *spec, void *data
if (node->id != idx)
continue;
ndata = kzalloc(sizeof(*ndata), GFP_KERNEL);
ndata = kzalloc_obj(*ndata, GFP_KERNEL);
if (!ndata)
return ERR_PTR(-ENOMEM);

View File

@@ -958,7 +958,7 @@ emc_of_icc_xlate_extended(const struct of_phandle_args *spec, void *data)
if (node->id != TEGRA_ICC_EMEM)
continue;
ndata = kzalloc(sizeof(*ndata), GFP_KERNEL);
ndata = kzalloc_obj(*ndata, GFP_KERNEL);
if (!ndata)
return ERR_PTR(-ENOMEM);

View File

@@ -401,7 +401,7 @@ tegra20_mc_of_icc_xlate_extended(const struct of_phandle_args *spec, void *data)
if (node->id != idx)
continue;
ndata = kzalloc(sizeof(*ndata), GFP_KERNEL);
ndata = kzalloc_obj(*ndata, GFP_KERNEL);
if (!ndata)
return ERR_PTR(-ENOMEM);
@@ -615,7 +615,7 @@ static int tegra20_mc_stats_show(struct seq_file *s, void *unused)
struct tegra20_mc_client_stat *stats;
unsigned int i;
stats = kcalloc(mc->soc->num_clients + 1, sizeof(*stats), GFP_KERNEL);
stats = kzalloc_objs(*stats, mc->soc->num_clients + 1, GFP_KERNEL);
if (!stats)
return -ENOMEM;

View File

@@ -1476,7 +1476,7 @@ emc_of_icc_xlate_extended(const struct of_phandle_args *spec, void *data)
if (node->id != TEGRA_ICC_EMEM)
continue;
ndata = kzalloc(sizeof(*ndata), GFP_KERNEL);
ndata = kzalloc_obj(*ndata, GFP_KERNEL);
if (!ndata)
return ERR_PTR(-ENOMEM);

View File

@@ -1344,7 +1344,7 @@ tegra30_mc_of_icc_xlate_extended(const struct of_phandle_args *spec, void *data)
if (node->id != idx)
continue;
ndata = kzalloc(sizeof(*ndata), GFP_KERNEL);
ndata = kzalloc_obj(*ndata, GFP_KERNEL);
if (!ndata)
return ERR_PTR(-ENOMEM);