summaryrefslogtreecommitdiff
path: root/arch/x86/platform
diff options
context:
space:
mode:
authorKees Cook <kees@kernel.org>2026-02-20 23:49:23 -0800
committerKees Cook <kees@kernel.org>2026-02-21 01:02:28 -0800
commit69050f8d6d075dc01af7a5f2f550a8067510366f (patch)
treebb265f94d9dfa7876c06a5d9f88673d496a15341 /arch/x86/platform
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (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 'arch/x86/platform')
-rw-r--r--arch/x86/platform/efi/runtime-map.c4
-rw-r--r--arch/x86/platform/geode/geode-common.c4
2 files changed, 4 insertions, 4 deletions
diff --git a/arch/x86/platform/efi/runtime-map.c b/arch/x86/platform/efi/runtime-map.c
index a6f02cef3ca2..77699893b5bb 100644
--- a/arch/x86/platform/efi/runtime-map.c
+++ b/arch/x86/platform/efi/runtime-map.c
@@ -114,7 +114,7 @@ add_sysfs_runtime_map_entry(struct kobject *kobj, int nr,
return ERR_PTR(-ENOMEM);
}
- entry = kzalloc(sizeof(*entry), GFP_KERNEL);
+ entry = kzalloc_obj(*entry, GFP_KERNEL);
if (!entry) {
kset_unregister(map_kset);
map_kset = NULL;
@@ -166,7 +166,7 @@ static int __init efi_runtime_map_init(void)
if (!efi_enabled(EFI_MEMMAP) || !efi_kobj)
return 0;
- map_entries = kcalloc(efi.memmap.nr_map, sizeof(entry), GFP_KERNEL);
+ map_entries = kzalloc_objs(entry, efi.memmap.nr_map, GFP_KERNEL);
if (!map_entries) {
ret = -ENOMEM;
goto out;
diff --git a/arch/x86/platform/geode/geode-common.c b/arch/x86/platform/geode/geode-common.c
index 8fd78e60bf15..f3c9eff2d374 100644
--- a/arch/x86/platform/geode/geode-common.c
+++ b/arch/x86/platform/geode/geode-common.c
@@ -113,7 +113,7 @@ int __init geode_create_leds(const char *label, const struct geode_led *leds,
return -EINVAL;
}
- swnodes = kcalloc(n_leds, sizeof(*swnodes), GFP_KERNEL);
+ swnodes = kzalloc_objs(*swnodes, n_leds, GFP_KERNEL);
if (!swnodes)
return -ENOMEM;
@@ -121,7 +121,7 @@ int __init geode_create_leds(const char *label, const struct geode_led *leds,
* Each LED is represented by 3 properties: "gpios",
* "linux,default-trigger", and am empty terminator.
*/
- props = kcalloc(n_leds * 3, sizeof(*props), GFP_KERNEL);
+ props = kzalloc_objs(*props, n_leds * 3, GFP_KERNEL);
if (!props) {
err = -ENOMEM;
goto err_free_swnodes;