summaryrefslogtreecommitdiff
path: root/arch/x86/hyperv
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/hyperv
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/hyperv')
-rw-r--r--arch/x86/hyperv/hv_init.c5
-rw-r--r--arch/x86/hyperv/irqdomain.c2
-rw-r--r--arch/x86/hyperv/ivm.c4
3 files changed, 5 insertions, 6 deletions
diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index 5dbe9bd67891..e945ed623027 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -467,9 +467,8 @@ void __init hyperv_init(void)
if (hv_isolation_type_tdx())
hv_vp_assist_page = NULL;
else
- hv_vp_assist_page = kcalloc(nr_cpu_ids,
- sizeof(*hv_vp_assist_page),
- GFP_KERNEL);
+ hv_vp_assist_page = kzalloc_objs(*hv_vp_assist_page, nr_cpu_ids,
+ GFP_KERNEL);
if (!hv_vp_assist_page) {
ms_hyperv.hints &= ~HV_X64_ENLIGHTENED_VMCS_RECOMMENDED;
diff --git a/arch/x86/hyperv/irqdomain.c b/arch/x86/hyperv/irqdomain.c
index c3ba12b1bc07..365e364268d9 100644
--- a/arch/x86/hyperv/irqdomain.c
+++ b/arch/x86/hyperv/irqdomain.c
@@ -248,7 +248,7 @@ static void hv_irq_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
return;
}
- stored_entry = kzalloc(sizeof(*stored_entry), GFP_ATOMIC);
+ stored_entry = kzalloc_obj(*stored_entry, GFP_ATOMIC);
if (!stored_entry) {
pr_debug("%s: failed to allocate chip data\n", __func__);
return;
diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c
index be7fad43a88d..07f125668852 100644
--- a/arch/x86/hyperv/ivm.c
+++ b/arch/x86/hyperv/ivm.c
@@ -531,7 +531,7 @@ static int hv_list_enc_add(const u64 *pfn_list, int count)
raw_spin_unlock_irqrestore(&hv_list_enc_lock, flags);
/* No adjacent region found -- create a new one */
- ent = kzalloc(sizeof(struct hv_enc_pfn_region), GFP_KERNEL);
+ ent = kzalloc_obj(struct hv_enc_pfn_region, GFP_KERNEL);
if (!ent)
return -ENOMEM;
@@ -598,7 +598,7 @@ unlock_done:
unlock_split:
raw_spin_unlock_irqrestore(&hv_list_enc_lock, flags);
- ent = kzalloc(sizeof(struct hv_enc_pfn_region), GFP_KERNEL);
+ ent = kzalloc_obj(struct hv_enc_pfn_region, GFP_KERNEL);
if (!ent)
return -ENOMEM;