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/thermal/testing | |
| 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/thermal/testing')
| -rw-r--r-- | drivers/thermal/testing/zone.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/drivers/thermal/testing/zone.c b/drivers/thermal/testing/zone.c index c12c405225bb..014e6e5f0e83 100644 --- a/drivers/thermal/testing/zone.c +++ b/drivers/thermal/testing/zone.c @@ -186,12 +186,13 @@ int tt_add_tz(void) { int ret; - struct tt_thermal_zone *tt_zone __free(kfree) = kzalloc(sizeof(*tt_zone), - GFP_KERNEL); + struct tt_thermal_zone *tt_zone __free(kfree) = kzalloc_obj(*tt_zone, + GFP_KERNEL); if (!tt_zone) return -ENOMEM; - struct tt_work *tt_work __free(kfree) = kzalloc(sizeof(*tt_work), GFP_KERNEL); + struct tt_work *tt_work __free(kfree) = kzalloc_obj(*tt_work, + GFP_KERNEL); if (!tt_work) return -ENOMEM; @@ -244,7 +245,8 @@ int tt_del_tz(const char *arg) if (ret != 1) return -EINVAL; - struct tt_work *tt_work __free(kfree) = kzalloc(sizeof(*tt_work), GFP_KERNEL); + struct tt_work *tt_work __free(kfree) = kzalloc_obj(*tt_work, + GFP_KERNEL); if (!tt_work) return -ENOMEM; @@ -330,11 +332,13 @@ int tt_zone_add_trip(const char *arg) { int id; - struct tt_work *tt_work __free(kfree) = kzalloc(sizeof(*tt_work), GFP_KERNEL); + struct tt_work *tt_work __free(kfree) = kzalloc_obj(*tt_work, + GFP_KERNEL); if (!tt_work) return -ENOMEM; - struct tt_trip *tt_trip __free(kfree) = kzalloc(sizeof(*tt_trip), GFP_KERNEL); + struct tt_trip *tt_trip __free(kfree) = kzalloc_obj(*tt_trip, + GFP_KERNEL); if (!tt_trip) return -ENOMEM; @@ -391,8 +395,9 @@ static int tt_zone_register_tz(struct tt_thermal_zone *tt_zone) if (tt_zone->tz) return -EINVAL; - struct thermal_trip *trips __free(kfree) = kcalloc(tt_zone->num_trips, - sizeof(*trips), GFP_KERNEL); + struct thermal_trip *trips __free(kfree) = kzalloc_objs(*trips, + tt_zone->num_trips, + GFP_KERNEL); if (!trips) return -ENOMEM; |
