From 69050f8d6d075dc01af7a5f2f550a8067510366f Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Fri, 20 Feb 2026 23:49:23 -0800 Subject: 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 --- drivers/net/tun.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/net/tun.c') diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 8192740357a0..fcddbeb6d36a 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -318,7 +318,7 @@ static struct tun_flow_entry *tun_flow_create(struct tun_struct *tun, struct hlist_head *head, u32 rxhash, u16 queue_index) { - struct tun_flow_entry *e = kmalloc(sizeof(*e), GFP_ATOMIC); + struct tun_flow_entry *e = kmalloc_obj(*e, GFP_ATOMIC); if (e) { netif_info(tun, tx_queued, tun->dev, @@ -2228,7 +2228,7 @@ static int __tun_set_ebpf(struct tun_struct *tun, struct tun_prog *old, *new = NULL; if (prog) { - new = kmalloc(sizeof(*new), GFP_KERNEL); + new = kmalloc_obj(*new, GFP_KERNEL); if (!new) return -ENOMEM; new->prog = prog; @@ -3605,7 +3605,7 @@ static int tun_queue_resize(struct tun_struct *tun) int n = tun->numqueues + tun->numdisabled; int ret, i; - rings = kmalloc_array(n, sizeof(*rings), GFP_KERNEL); + rings = kmalloc_objs(*rings, n, GFP_KERNEL); if (!rings) return -ENOMEM; -- cgit v1.2.3