summaryrefslogtreecommitdiff
path: root/include/net
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 /include/net
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 'include/net')
-rw-r--r--include/net/act_api.h2
-rw-r--r--include/net/fq_impl.h2
-rw-r--r--include/net/iucv/iucv.h2
-rw-r--r--include/net/tc_act/tc_gate.h2
-rw-r--r--include/net/udp.h4
5 files changed, 6 insertions, 6 deletions
diff --git a/include/net/act_api.h b/include/net/act_api.h
index 91a24b5e0b93..453d6e18851b 100644
--- a/include/net/act_api.h
+++ b/include/net/act_api.h
@@ -159,7 +159,7 @@ int tc_action_net_init(struct net *net, struct tc_action_net *tn,
{
int err = 0;
- tn->idrinfo = kmalloc(sizeof(*tn->idrinfo), GFP_KERNEL);
+ tn->idrinfo = kmalloc_obj(*tn->idrinfo, GFP_KERNEL);
if (!tn->idrinfo)
return -ENOMEM;
tn->ops = ops;
diff --git a/include/net/fq_impl.h b/include/net/fq_impl.h
index 9467e33dfb36..171ee6f7aa83 100644
--- a/include/net/fq_impl.h
+++ b/include/net/fq_impl.h
@@ -358,7 +358,7 @@ static int fq_init(struct fq *fq, int flows_cnt)
fq->limit = 8192;
fq->memory_limit = 16 << 20; /* 16 MBytes */
- fq->flows = kvcalloc(fq->flows_cnt, sizeof(fq->flows[0]), GFP_KERNEL);
+ fq->flows = kvzalloc_objs(fq->flows[0], fq->flows_cnt, GFP_KERNEL);
if (!fq->flows)
return -ENOMEM;
diff --git a/include/net/iucv/iucv.h b/include/net/iucv/iucv.h
index 5606ed6e7084..18f511da9a09 100644
--- a/include/net/iucv/iucv.h
+++ b/include/net/iucv/iucv.h
@@ -211,7 +211,7 @@ static inline struct iucv_path *iucv_path_alloc(u16 msglim, u8 flags, gfp_t gfp)
{
struct iucv_path *path;
- path = kzalloc(sizeof(struct iucv_path), gfp);
+ path = kzalloc_obj(struct iucv_path, gfp);
if (path) {
path->msglim = msglim;
path->flags = flags;
diff --git a/include/net/tc_act/tc_gate.h b/include/net/tc_act/tc_gate.h
index c1a67149c6b6..b147a3bb1a46 100644
--- a/include/net/tc_act/tc_gate.h
+++ b/include/net/tc_act/tc_gate.h
@@ -114,7 +114,7 @@ static inline struct action_gate_entry
if (i != num_entries)
return NULL;
- oe = kcalloc(num_entries, sizeof(*oe), GFP_ATOMIC);
+ oe = kzalloc_objs(*oe, num_entries, GFP_ATOMIC);
if (!oe)
return NULL;
diff --git a/include/net/udp.h b/include/net/udp.h
index 700dbedcb15f..24491111477a 100644
--- a/include/net/udp.h
+++ b/include/net/udp.h
@@ -294,8 +294,8 @@ static inline int udp_lib_init_sock(struct sock *sk)
up->forward_threshold = sk->sk_rcvbuf >> 2;
set_bit(SOCK_CUSTOM_SOCKOPT, &sk->sk_socket->flags);
- up->udp_prod_queue = kcalloc(nr_node_ids, sizeof(*up->udp_prod_queue),
- GFP_KERNEL);
+ up->udp_prod_queue = kzalloc_objs(*up->udp_prod_queue, nr_node_ids,
+ GFP_KERNEL);
if (!up->udp_prod_queue)
return -ENOMEM;
for (int i = 0; i < nr_node_ids; i++)