diff options
| author | Kees Cook <kees@kernel.org> | 2026-02-20 23:49:23 -0800 |
|---|---|---|
| committer | Kees Cook <kees@kernel.org> | 2026-02-21 01:02:28 -0800 |
| commit | 69050f8d6d075dc01af7a5f2f550a8067510366f (patch) | |
| tree | bb265f94d9dfa7876c06a5d9f88673d496a15341 /drivers/memory | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
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>
Diffstat (limited to 'drivers/memory')
| -rw-r--r-- | drivers/memory/samsung/exynos-srom.c | 2 | ||||
| -rw-r--r-- | drivers/memory/tegra/tegra124-emc.c | 2 | ||||
| -rw-r--r-- | drivers/memory/tegra/tegra124.c | 2 | ||||
| -rw-r--r-- | drivers/memory/tegra/tegra20-emc.c | 2 | ||||
| -rw-r--r-- | drivers/memory/tegra/tegra20.c | 4 | ||||
| -rw-r--r-- | drivers/memory/tegra/tegra30-emc.c | 2 | ||||
| -rw-r--r-- | drivers/memory/tegra/tegra30.c | 2 |
7 files changed, 8 insertions, 8 deletions
diff --git a/drivers/memory/samsung/exynos-srom.c b/drivers/memory/samsung/exynos-srom.c index d913fb901973..1863c85642dd 100644 --- a/drivers/memory/samsung/exynos-srom.c +++ b/drivers/memory/samsung/exynos-srom.c @@ -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; diff --git a/drivers/memory/tegra/tegra124-emc.c b/drivers/memory/tegra/tegra124-emc.c index 9978ff911c47..68496f9012ff 100644 --- a/drivers/memory/tegra/tegra124-emc.c +++ b/drivers/memory/tegra/tegra124-emc.c @@ -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); diff --git a/drivers/memory/tegra/tegra124.c b/drivers/memory/tegra/tegra124.c index 9d7393e19f12..965bfab127f5 100644 --- a/drivers/memory/tegra/tegra124.c +++ b/drivers/memory/tegra/tegra124.c @@ -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); diff --git a/drivers/memory/tegra/tegra20-emc.c b/drivers/memory/tegra/tegra20-emc.c index 398cb8ae2e38..48a546315d1c 100644 --- a/drivers/memory/tegra/tegra20-emc.c +++ b/drivers/memory/tegra/tegra20-emc.c @@ -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); diff --git a/drivers/memory/tegra/tegra20.c b/drivers/memory/tegra/tegra20.c index a3022e715dee..40bee3ff4a45 100644 --- a/drivers/memory/tegra/tegra20.c +++ b/drivers/memory/tegra/tegra20.c @@ -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; diff --git a/drivers/memory/tegra/tegra30-emc.c b/drivers/memory/tegra/tegra30-emc.c index 914116d8ec16..8226cadc1f8f 100644 --- a/drivers/memory/tegra/tegra30-emc.c +++ b/drivers/memory/tegra/tegra30-emc.c @@ -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); diff --git a/drivers/memory/tegra/tegra30.c b/drivers/memory/tegra/tegra30.c index d3e685c8431f..d9f255da5c0e 100644 --- a/drivers/memory/tegra/tegra30.c +++ b/drivers/memory/tegra/tegra30.c @@ -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); |
