summaryrefslogtreecommitdiff
path: root/drivers/net/tun.c
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/net/tun.c
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/net/tun.c')
-rw-r--r--drivers/net/tun.c6
1 files changed, 3 insertions, 3 deletions
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;