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/acpi/scan.c | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
| download | lwn-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.gz lwn-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/acpi/scan.c')
| -rw-r--r-- | drivers/acpi/scan.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 565a84a7d7bc..490242bf161b 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -757,8 +757,8 @@ int acpi_device_add(struct acpi_device *device) if (result) goto err_unlock; } else { - acpi_device_bus_id = kzalloc(sizeof(*acpi_device_bus_id), - GFP_KERNEL); + acpi_device_bus_id = kzalloc_obj(*acpi_device_bus_id, + GFP_KERNEL); if (!acpi_device_bus_id) { result = -ENOMEM; goto err_unlock; @@ -1330,7 +1330,7 @@ static void acpi_add_id(struct acpi_device_pnp *pnp, const char *dev_id) { struct acpi_hardware_id *id; - id = kmalloc(sizeof(*id), GFP_KERNEL); + id = kmalloc_obj(*id, GFP_KERNEL); if (!id) return; @@ -1568,7 +1568,7 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map) ret = acpi_dev_get_dma_resources(adev, &list); if (ret > 0) { - r = kcalloc(ret + 1, sizeof(*r), GFP_KERNEL); + r = kzalloc_objs(*r, ret + 1, GFP_KERNEL); if (!r) { ret = -ENOMEM; goto out; @@ -1863,7 +1863,7 @@ static int acpi_add_single_object(struct acpi_device **child, bool release_dep_lock = false; int result; - device = kzalloc(sizeof(struct acpi_device), GFP_KERNEL); + device = kzalloc_obj(struct acpi_device, GFP_KERNEL); if (!device) return -ENOMEM; @@ -2028,7 +2028,7 @@ int acpi_scan_add_dep(acpi_handle handle, struct acpi_handle_list *dep_devices) if (skip) continue; - dep = kzalloc(sizeof(*dep), GFP_KERNEL); + dep = kzalloc_obj(*dep, GFP_KERNEL); if (!dep) continue; @@ -2225,7 +2225,7 @@ static void acpi_default_enumeration(struct acpi_device *device) * other device objects have been processed and PCI has claimed * BARs in case there are resource conflicts. */ - sd = kmalloc(sizeof(*sd), GFP_KERNEL); + sd = kmalloc_obj(*sd, GFP_KERNEL); if (sd) { sd->adev = device; list_add_tail(&sd->node, &acpi_scan_system_dev_list); @@ -2899,7 +2899,7 @@ void acpi_scan_table_notify(void) if (!acpi_scan_initialized) return; - work = kmalloc(sizeof(*work), GFP_KERNEL); + work = kmalloc_obj(*work, GFP_KERNEL); if (!work) return; |
