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/opp/core.c | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
| download | linux-next-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.gz linux-next-69050f8d6d075dc01af7a5f2f550a8067510366f.zip | |
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/opp/core.c')
| -rw-r--r-- | drivers/opp/core.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/drivers/opp/core.c b/drivers/opp/core.c index ae43c656f108..a109d4dd5316 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1532,7 +1532,7 @@ static struct opp_table *_allocate_opp_table(struct device *dev, int index) * Allocate a new OPP table. In the infrequent case where a new * device is needed to be added, we pay this penalty. */ - opp_table = kzalloc(sizeof(*opp_table), GFP_KERNEL); + opp_table = kzalloc_obj(*opp_table, GFP_KERNEL); if (!opp_table) return ERR_PTR(-ENOMEM); @@ -2260,9 +2260,8 @@ static int _opp_set_regulators(struct opp_table *opp_table, struct device *dev, if (opp_table->regulators) return 0; - opp_table->regulators = kmalloc_array(count, - sizeof(*opp_table->regulators), - GFP_KERNEL); + opp_table->regulators = kmalloc_objs(*opp_table->regulators, count, + GFP_KERNEL); if (!opp_table->regulators) return -ENOMEM; @@ -2364,8 +2363,7 @@ static int _opp_set_clknames(struct opp_table *opp_table, struct device *dev, if (opp_table->clks) return 0; - opp_table->clks = kmalloc_array(count, sizeof(*opp_table->clks), - GFP_KERNEL); + opp_table->clks = kmalloc_objs(*opp_table->clks, count, GFP_KERNEL); if (!opp_table->clks) return -ENOMEM; @@ -2550,7 +2548,7 @@ int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config) unsigned int id; int ret; - data = kmalloc(sizeof(*data), GFP_KERNEL); + data = kmalloc_obj(*data, GFP_KERNEL); if (!data) return -ENOMEM; |
