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/net/hyperv | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (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/net/hyperv')
| -rw-r--r-- | drivers/net/hyperv/netvsc.c | 7 | ||||
| -rw-r--r-- | drivers/net/hyperv/netvsc_drv.c | 9 | ||||
| -rw-r--r-- | drivers/net/hyperv/rndis_filter.c | 4 |
3 files changed, 9 insertions, 11 deletions
diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c index 60a4629fe6ba..d9fa2fc4c43c 100644 --- a/drivers/net/hyperv/netvsc.c +++ b/drivers/net/hyperv/netvsc.c @@ -129,7 +129,7 @@ static struct netvsc_device *alloc_net_device(void) { struct netvsc_device *net_device; - net_device = kzalloc(sizeof(struct netvsc_device), GFP_KERNEL); + net_device = kzalloc_obj(struct netvsc_device, GFP_KERNEL); if (!net_device) return NULL; @@ -1025,9 +1025,8 @@ static int netvsc_dma_map(struct hv_device *hv_dev, if (!hv_is_isolation_supported()) return 0; - packet->dma_range = kcalloc(page_count, - sizeof(*packet->dma_range), - GFP_ATOMIC); + packet->dma_range = kzalloc_objs(*packet->dma_range, page_count, + GFP_ATOMIC); if (!packet->dma_range) return -ENOMEM; diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c index cbd52cb79268..1a3f2a35519f 100644 --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -712,7 +712,7 @@ void netvsc_linkstatus_callback(struct net_device *net, if (net->reg_state != NETREG_REGISTERED) return; - event = kzalloc(sizeof(*event), GFP_ATOMIC); + event = kzalloc_obj(*event, GFP_ATOMIC); if (!event) return; event->event = indicate->status; @@ -931,7 +931,7 @@ struct netvsc_device_info *netvsc_devinfo_get(struct netvsc_device *nvdev) struct netvsc_device_info *dev_info; struct bpf_prog *prog; - dev_info = kzalloc(sizeof(*dev_info), GFP_ATOMIC); + dev_info = kzalloc_obj(*dev_info, GFP_ATOMIC); if (!dev_info) return NULL; @@ -1524,9 +1524,8 @@ static void netvsc_get_ethtool_stats(struct net_device *dev, data[i++] = xdp_tx; } - pcpu_sum = kvmalloc_array(nr_cpu_ids, - sizeof(struct netvsc_ethtool_pcpu_stats), - GFP_KERNEL); + pcpu_sum = kvmalloc_objs(struct netvsc_ethtool_pcpu_stats, nr_cpu_ids, + GFP_KERNEL); if (!pcpu_sum) return; diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c index c35f9685b6bf..2fa77dc21d7e 100644 --- a/drivers/net/hyperv/rndis_filter.c +++ b/drivers/net/hyperv/rndis_filter.c @@ -64,7 +64,7 @@ static struct rndis_device *get_rndis_device(void) { struct rndis_device *device; - device = kzalloc(sizeof(struct rndis_device), GFP_KERNEL); + device = kzalloc_obj(struct rndis_device, GFP_KERNEL); if (!device) return NULL; @@ -87,7 +87,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev, struct rndis_set_request *set; unsigned long flags; - request = kzalloc(sizeof(struct rndis_request), GFP_KERNEL); + request = kzalloc_obj(struct rndis_request, GFP_KERNEL); if (!request) return NULL; |
