summaryrefslogtreecommitdiff
path: root/drivers/hv
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 /drivers/hv
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 'drivers/hv')
-rw-r--r--drivers/hv/channel_mgmt.c2
-rw-r--r--drivers/hv/connection.c5
-rw-r--r--drivers/hv/hv.c4
-rw-r--r--drivers/hv/hv_balloon.c2
-rw-r--r--drivers/hv/hv_kvp.c4
-rw-r--r--drivers/hv/hv_proc.c2
-rw-r--r--drivers/hv/hv_snapshot.c4
-rw-r--r--drivers/hv/hv_utils_transport.c2
-rw-r--r--drivers/hv/mshv_debugfs.c16
-rw-r--r--drivers/hv/mshv_eventfd.c6
-rw-r--r--drivers/hv/mshv_irq.c4
-rw-r--r--drivers/hv/mshv_root_main.c6
-rw-r--r--drivers/hv/mshv_synic.c2
-rw-r--r--drivers/hv/mshv_vtl_main.c6
-rw-r--r--drivers/hv/ring_buffer.c5
-rw-r--r--drivers/hv/vmbus_drv.c10
16 files changed, 38 insertions, 42 deletions
diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
index 74fed2c073d4..7c77ada12b2e 100644
--- a/drivers/hv/channel_mgmt.c
+++ b/drivers/hv/channel_mgmt.c
@@ -354,7 +354,7 @@ static struct vmbus_channel *alloc_channel(void)
{
struct vmbus_channel *channel;
- channel = kzalloc(sizeof(*channel), GFP_ATOMIC);
+ channel = kzalloc_obj(*channel, GFP_ATOMIC);
if (!channel)
return NULL;
diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
index 5d9cb5bf2d62..16b9959dba7e 100644
--- a/drivers/hv/connection.c
+++ b/drivers/hv/connection.c
@@ -313,9 +313,8 @@ int vmbus_connect(void)
pr_info("Vmbus version:%d.%d\n",
version >> 16, version & 0xFFFF);
- vmbus_connection.channels = kcalloc(MAX_CHANNEL_RELIDS,
- sizeof(struct vmbus_channel *),
- GFP_KERNEL);
+ vmbus_connection.channels = kzalloc_objs(struct vmbus_channel *,
+ MAX_CHANNEL_RELIDS, GFP_KERNEL);
if (vmbus_connection.channels == NULL) {
ret = -ENOMEM;
goto cleanup;
diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
index ea6835638505..4a2348b7f8a2 100644
--- a/drivers/hv/hv.c
+++ b/drivers/hv/hv.c
@@ -183,8 +183,8 @@ int hv_synic_alloc(void)
memset(hv_cpu, 0, sizeof(*hv_cpu));
}
- hv_context.hv_numa_map = kcalloc(nr_node_ids, sizeof(struct cpumask),
- GFP_KERNEL);
+ hv_context.hv_numa_map = kzalloc_objs(struct cpumask, nr_node_ids,
+ GFP_KERNEL);
if (!hv_context.hv_numa_map) {
pr_err("Unable to allocate NUMA map\n");
goto err;
diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
index 2b4080e51f97..a848400a59a2 100644
--- a/drivers/hv/hv_balloon.c
+++ b/drivers/hv/hv_balloon.c
@@ -801,7 +801,7 @@ static int pfn_covered(unsigned long start_pfn, unsigned long pfn_cnt)
* is, create a gap and update covered_end_pfn.
*/
if (has->covered_end_pfn != start_pfn) {
- gap = kzalloc(sizeof(struct hv_hotadd_gap), GFP_ATOMIC);
+ gap = kzalloc_obj(struct hv_hotadd_gap, GFP_ATOMIC);
if (!gap) {
ret = -ENOMEM;
break;
diff --git a/drivers/hv/hv_kvp.c b/drivers/hv/hv_kvp.c
index 62795f6cbb00..29ef1dc5c184 100644
--- a/drivers/hv/hv_kvp.c
+++ b/drivers/hv/hv_kvp.c
@@ -134,7 +134,7 @@ kvp_register(int reg_value)
struct hv_kvp_msg *kvp_msg;
char *version;
- kvp_msg = kzalloc(sizeof(*kvp_msg), GFP_KERNEL);
+ kvp_msg = kzalloc_obj(*kvp_msg, GFP_KERNEL);
if (kvp_msg) {
version = kvp_msg->body.kvp_register.version;
@@ -385,7 +385,7 @@ kvp_send_key(struct work_struct *dummy)
if (kvp_transaction.state != HVUTIL_HOSTMSG_RECEIVED)
return;
- message = kzalloc(sizeof(*message), GFP_KERNEL);
+ message = kzalloc_obj(*message, GFP_KERNEL);
if (!message)
return;
diff --git a/drivers/hv/hv_proc.c b/drivers/hv/hv_proc.c
index 5f4fd9c3231c..216a0e8fd15b 100644
--- a/drivers/hv/hv_proc.c
+++ b/drivers/hv/hv_proc.c
@@ -40,7 +40,7 @@ int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
return -ENOMEM;
pages = page_address(page);
- counts = kcalloc(HV_DEPOSIT_MAX, sizeof(int), GFP_KERNEL);
+ counts = kzalloc_objs(int, HV_DEPOSIT_MAX, GFP_KERNEL);
if (!counts) {
free_page((unsigned long)pages);
return -ENOMEM;
diff --git a/drivers/hv/hv_snapshot.c b/drivers/hv/hv_snapshot.c
index 2e7f537d53cf..50f9348789ee 100644
--- a/drivers/hv/hv_snapshot.c
+++ b/drivers/hv/hv_snapshot.c
@@ -184,7 +184,7 @@ static void vss_send_op(void)
return;
}
- vss_msg = kzalloc(sizeof(*vss_msg), GFP_KERNEL);
+ vss_msg = kzalloc_obj(*vss_msg, GFP_KERNEL);
if (!vss_msg)
return;
@@ -424,7 +424,7 @@ int hv_vss_pre_suspend(void)
* write() will fail with EINVAL (see vss_on_msg()), and the daemon
* will reset the device by closing and re-opening it.
*/
- vss_msg = kzalloc(sizeof(*vss_msg), GFP_KERNEL);
+ vss_msg = kzalloc_obj(*vss_msg, GFP_KERNEL);
if (!vss_msg)
return -ENOMEM;
diff --git a/drivers/hv/hv_utils_transport.c b/drivers/hv/hv_utils_transport.c
index b3de35ff6334..43b7ffae8852 100644
--- a/drivers/hv/hv_utils_transport.c
+++ b/drivers/hv/hv_utils_transport.c
@@ -274,7 +274,7 @@ struct hvutil_transport *hvutil_transport_init(const char *name,
{
struct hvutil_transport *hvt;
- hvt = kzalloc(sizeof(*hvt), GFP_KERNEL);
+ hvt = kzalloc_obj(*hvt, GFP_KERNEL);
if (!hvt)
return NULL;
diff --git a/drivers/hv/mshv_debugfs.c b/drivers/hv/mshv_debugfs.c
index ebf2549eb44d..6a080d728836 100644
--- a/drivers/hv/mshv_debugfs.c
+++ b/drivers/hv/mshv_debugfs.c
@@ -156,9 +156,8 @@ static int __init mshv_debugfs_lp_create(struct dentry *parent)
struct dentry *lp_dir;
int err, lp_index;
- mshv_lps_stats = kcalloc(mshv_lps_count,
- sizeof(*mshv_lps_stats),
- GFP_KERNEL_ACCOUNT);
+ mshv_lps_stats = kzalloc_objs(*mshv_lps_stats, mshv_lps_count,
+ GFP_KERNEL_ACCOUNT);
if (!mshv_lps_stats)
return -ENOMEM;
@@ -329,8 +328,8 @@ static int mshv_debugfs_partition_stats_create(u64 partition_id,
struct hv_stats_page **pstats;
int err;
- pstats = kcalloc(NUM_STATS_AREAS, sizeof(struct hv_stats_page *),
- GFP_KERNEL_ACCOUNT);
+ pstats = kzalloc_objs(struct hv_stats_page *, NUM_STATS_AREAS,
+ GFP_KERNEL_ACCOUNT);
if (!pstats)
return -ENOMEM;
@@ -472,8 +471,8 @@ static int __init parent_vp_debugfs_create(u32 vp_index,
struct hv_stats_page **pstats;
int err;
- pstats = kcalloc(NUM_STATS_AREAS, sizeof(struct hv_stats_page *),
- GFP_KERNEL_ACCOUNT);
+ pstats = kzalloc_objs(struct hv_stats_page *, NUM_STATS_AREAS,
+ GFP_KERNEL_ACCOUNT);
if (!pstats)
return -ENOMEM;
@@ -512,8 +511,7 @@ static int __init mshv_debugfs_parent_partition_create(void)
if (err)
goto remove_debugfs_partition;
- parent_vp_stats = kcalloc(nr_cpu_ids, sizeof(*parent_vp_stats),
- GFP_KERNEL);
+ parent_vp_stats = kzalloc_objs(*parent_vp_stats, nr_cpu_ids, GFP_KERNEL);
if (!parent_vp_stats) {
err = -ENOMEM;
goto remove_debugfs_partition;
diff --git a/drivers/hv/mshv_eventfd.c b/drivers/hv/mshv_eventfd.c
index 492c6258045c..5b3c09f08a1e 100644
--- a/drivers/hv/mshv_eventfd.c
+++ b/drivers/hv/mshv_eventfd.c
@@ -394,7 +394,7 @@ static int mshv_irqfd_assign(struct mshv_partition *pt,
CLASS(fd, f)(args->fd);
- irqfd = kzalloc(sizeof(*irqfd), GFP_KERNEL);
+ irqfd = kzalloc_obj(*irqfd, GFP_KERNEL);
if (!irqfd)
return -ENOMEM;
@@ -439,7 +439,7 @@ static int mshv_irqfd_assign(struct mshv_partition *pt,
}
if (!irqfd->irqfd_resampler) {
- rp = kzalloc(sizeof(*rp), GFP_KERNEL_ACCOUNT);
+ rp = kzalloc_obj(*rp, GFP_KERNEL_ACCOUNT);
if (!rp) {
ret = -ENOMEM;
mutex_unlock(&pt->irqfds_resampler_lock);
@@ -707,7 +707,7 @@ static int mshv_assign_ioeventfd(struct mshv_partition *pt,
if (IS_ERR(eventfd))
return PTR_ERR(eventfd);
- p = kzalloc(sizeof(*p), GFP_KERNEL);
+ p = kzalloc_obj(*p, GFP_KERNEL);
if (!p) {
ret = -ENOMEM;
goto fail;
diff --git a/drivers/hv/mshv_irq.c b/drivers/hv/mshv_irq.c
index 798e7e1ab06e..02c56fc3a498 100644
--- a/drivers/hv/mshv_irq.c
+++ b/drivers/hv/mshv_irq.c
@@ -37,8 +37,8 @@ int mshv_update_routing_table(struct mshv_partition *partition,
}
nr_rt_entries += 1;
- new = kzalloc(struct_size(new, mshv_girq_info_tbl, nr_rt_entries),
- GFP_KERNEL_ACCOUNT);
+ new = kzalloc_flex(*new, mshv_girq_info_tbl, nr_rt_entries,
+ GFP_KERNEL_ACCOUNT);
if (!new)
return -ENOMEM;
diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
index e6509c980763..4715d23d22f2 100644
--- a/drivers/hv/mshv_root_main.c
+++ b/drivers/hv/mshv_root_main.c
@@ -713,7 +713,7 @@ mshv_vp_ioctl_get_set_state_pfn(struct mshv_vp *vp,
return -EOVERFLOW;
/* Pin user pages so hypervisor can copy directly to them */
- pages = kcalloc(page_count, sizeof(struct page *), GFP_KERNEL);
+ pages = kzalloc_objs(struct page *, page_count, GFP_KERNEL);
if (!pages)
return -ENOMEM;
@@ -1072,7 +1072,7 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
if (ret)
goto unmap_ghcb_page;
- vp = kzalloc(sizeof(*vp), GFP_KERNEL);
+ vp = kzalloc_obj(*vp, GFP_KERNEL);
if (!vp)
goto unmap_stats_pages;
@@ -1977,7 +1977,7 @@ mshv_ioctl_create_partition(void __user *user_arg, struct device *module_dev)
if (ret)
return ret;
- partition = kzalloc(sizeof(*partition), GFP_KERNEL);
+ partition = kzalloc_obj(*partition, GFP_KERNEL);
if (!partition)
return -ENOMEM;
diff --git a/drivers/hv/mshv_synic.c b/drivers/hv/mshv_synic.c
index f8b0337cdc82..49e3a59ffb90 100644
--- a/drivers/hv/mshv_synic.c
+++ b/drivers/hv/mshv_synic.c
@@ -605,7 +605,7 @@ mshv_register_doorbell(u64 partition_id, doorbell_cb_t doorbell_cb, void *data,
union hv_port_id port_id = { 0 };
int ret;
- port_table_info = kmalloc(sizeof(*port_table_info), GFP_KERNEL);
+ port_table_info = kmalloc_obj(*port_table_info, GFP_KERNEL);
if (!port_table_info)
return -ENOMEM;
diff --git a/drivers/hv/mshv_vtl_main.c b/drivers/hv/mshv_vtl_main.c
index 7bbbce009732..916021a175f3 100644
--- a/drivers/hv/mshv_vtl_main.c
+++ b/drivers/hv/mshv_vtl_main.c
@@ -117,7 +117,7 @@ mshv_ioctl_create_vtl(void __user *user_arg, struct device *module_dev)
struct file *file;
int fd;
- vtl = kzalloc(sizeof(*vtl), GFP_KERNEL);
+ vtl = kzalloc_obj(*vtl, GFP_KERNEL);
if (!vtl)
return -ENOMEM;
@@ -393,7 +393,7 @@ static int mshv_vtl_ioctl_add_vtl0_mem(struct mshv_vtl *vtl, void __user *arg)
return -EFAULT;
}
- pgmap = kzalloc(sizeof(*pgmap), GFP_KERNEL);
+ pgmap = kzalloc_obj(*pgmap, GFP_KERNEL);
if (!pgmap)
return -ENOMEM;
@@ -1344,7 +1344,7 @@ static int __init mshv_vtl_init(void)
/*
* "mshv vtl mem dev" device is later used to setup VTL0 memory.
*/
- mem_dev = kzalloc(sizeof(*mem_dev), GFP_KERNEL);
+ mem_dev = kzalloc_obj(*mem_dev, GFP_KERNEL);
if (!mem_dev) {
ret = -ENOMEM;
goto free_low;
diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
index 3c421a7f78c0..db3c2537360f 100644
--- a/drivers/hv/ring_buffer.c
+++ b/drivers/hv/ring_buffer.c
@@ -196,9 +196,8 @@ int hv_ringbuffer_init(struct hv_ring_buffer_info *ring_info,
* First page holds struct hv_ring_buffer, do wraparound mapping for
* the rest.
*/
- pages_wraparound = kcalloc(page_cnt * 2 - 1,
- sizeof(struct page *),
- GFP_KERNEL);
+ pages_wraparound = kzalloc_objs(struct page *, page_cnt * 2 - 1,
+ GFP_KERNEL);
if (!pages_wraparound)
return -ENOMEM;
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 3e7a52918ce0..3119f68fd27b 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -756,7 +756,7 @@ static int vmbus_add_dynid(struct hv_driver *drv, guid_t *guid)
{
struct vmbus_dynid *dynid;
- dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
+ dynid = kzalloc_obj(*dynid, GFP_KERNEL);
if (!dynid)
return -ENOMEM;
@@ -1120,7 +1120,7 @@ static void __vmbus_on_msg_dpc(void *message_page_addr)
}
if (entry->handler_type == VMHT_BLOCKING) {
- ctx = kmalloc(struct_size(ctx, msg.payload, payload_size), GFP_ATOMIC);
+ ctx = kmalloc_flex(*ctx, msg.payload, payload_size, GFP_ATOMIC);
if (ctx == NULL)
return;
@@ -2156,7 +2156,7 @@ struct hv_device *vmbus_device_create(const guid_t *type,
{
struct hv_device *child_device_obj;
- child_device_obj = kzalloc(sizeof(struct hv_device), GFP_KERNEL);
+ child_device_obj = kzalloc_obj(struct hv_device, GFP_KERNEL);
if (!child_device_obj) {
pr_err("Unable to allocate device object for child device\n");
return NULL;
@@ -2318,7 +2318,7 @@ static acpi_status vmbus_walk_resources(struct acpi_resource *res, void *ctx)
if (end < 0x100000)
return AE_OK;
- new_res = kzalloc(sizeof(*new_res), GFP_ATOMIC);
+ new_res = kzalloc_obj(*new_res, GFP_ATOMIC);
if (!new_res)
return AE_NO_MEMORY;
@@ -2672,7 +2672,7 @@ static int vmbus_device_add(struct platform_device *pdev)
for_each_of_range(&parser, &range) {
struct resource *res;
- res = kzalloc(sizeof(*res), GFP_KERNEL);
+ res = kzalloc_obj(*res, GFP_KERNEL);
if (!res) {
vmbus_mmio_remove();
return -ENOMEM;