summaryrefslogtreecommitdiff
path: root/net/tipc
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 /net/tipc
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (diff)
downloadlwn-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.gz
lwn-69050f8d6d075dc01af7a5f2f550a8067510366f.zip
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 'net/tipc')
-rw-r--r--net/tipc/bcast.c2
-rw-r--r--net/tipc/bearer.c2
-rw-r--r--net/tipc/crypto.c8
-rw-r--r--net/tipc/discover.c2
-rw-r--r--net/tipc/group.c4
-rw-r--r--net/tipc/link.c2
-rw-r--r--net/tipc/monitor.c8
-rw-r--r--net/tipc/name_table.c10
-rw-r--r--net/tipc/netlink_compat.c9
-rw-r--r--net/tipc/node.c4
-rw-r--r--net/tipc/socket.c2
-rw-r--r--net/tipc/subscr.c2
-rw-r--r--net/tipc/topsrv.c6
-rw-r--r--net/tipc/udp_media.c4
14 files changed, 32 insertions, 33 deletions
diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c
index 114fef65f92e..c7c7f08eee9a 100644
--- a/net/tipc/bcast.c
+++ b/net/tipc/bcast.c
@@ -692,7 +692,7 @@ int tipc_bcast_init(struct net *net)
struct tipc_bc_base *bb = NULL;
struct tipc_link *l = NULL;
- bb = kzalloc(sizeof(*bb), GFP_KERNEL);
+ bb = kzalloc_obj(*bb, GFP_KERNEL);
if (!bb)
goto enomem;
tn->bcbase = bb;
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index ae1ddbf71853..a3bd1ef17558 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -322,7 +322,7 @@ static int tipc_enable_bearer(struct net *net, const char *name,
goto rejected;
}
- b = kzalloc(sizeof(*b), GFP_ATOMIC);
+ b = kzalloc_obj(*b, GFP_ATOMIC);
if (!b)
return -ENOMEM;
diff --git a/net/tipc/crypto.c b/net/tipc/crypto.c
index a3f9ca28c3d5..abd191a3ac4a 100644
--- a/net/tipc/crypto.c
+++ b/net/tipc/crypto.c
@@ -524,7 +524,7 @@ static int tipc_aead_init(struct tipc_aead **aead, struct tipc_aead_key *ukey,
return -EEXIST;
/* Allocate a new AEAD */
- tmp = kzalloc(sizeof(*tmp), GFP_ATOMIC);
+ tmp = kzalloc_obj(*tmp, GFP_ATOMIC);
if (unlikely(!tmp))
return -ENOMEM;
@@ -560,7 +560,7 @@ static int tipc_aead_init(struct tipc_aead **aead, struct tipc_aead_key *ukey,
break;
}
- tfm_entry = kmalloc(sizeof(*tfm_entry), GFP_KERNEL);
+ tfm_entry = kmalloc_obj(*tfm_entry, GFP_KERNEL);
if (unlikely(!tfm_entry)) {
crypto_free_aead(tfm);
err = -ENOMEM;
@@ -637,7 +637,7 @@ static int tipc_aead_clone(struct tipc_aead **dst, struct tipc_aead *src)
if (unlikely(*dst))
return -EEXIST;
- aead = kzalloc(sizeof(*aead), GFP_ATOMIC);
+ aead = kzalloc_obj(*aead, GFP_ATOMIC);
if (unlikely(!aead))
return -ENOMEM;
@@ -1472,7 +1472,7 @@ int tipc_crypto_start(struct tipc_crypto **crypto, struct net *net,
return -EEXIST;
/* Allocate crypto */
- c = kzalloc(sizeof(*c), GFP_ATOMIC);
+ c = kzalloc_obj(*c, GFP_ATOMIC);
if (!c)
return -ENOMEM;
diff --git a/net/tipc/discover.c b/net/tipc/discover.c
index 775fd4f3f072..3e54d2df5683 100644
--- a/net/tipc/discover.c
+++ b/net/tipc/discover.c
@@ -353,7 +353,7 @@ int tipc_disc_create(struct net *net, struct tipc_bearer *b,
struct tipc_net *tn = tipc_net(net);
struct tipc_discoverer *d;
- d = kmalloc(sizeof(*d), GFP_ATOMIC);
+ d = kmalloc_obj(*d, GFP_ATOMIC);
if (!d)
return -ENOMEM;
d->skb = tipc_buf_acquire(MAX_H_SIZE + NODE_ID_LEN, GFP_ATOMIC);
diff --git a/net/tipc/group.c b/net/tipc/group.c
index 3e137d8c9d2f..e0e6227b433b 100644
--- a/net/tipc/group.c
+++ b/net/tipc/group.c
@@ -169,7 +169,7 @@ struct tipc_group *tipc_group_create(struct net *net, u32 portid,
struct tipc_group *grp;
u32 type = mreq->type;
- grp = kzalloc(sizeof(*grp), GFP_ATOMIC);
+ grp = kzalloc_obj(*grp, GFP_ATOMIC);
if (!grp)
return NULL;
tipc_nlist_init(&grp->dests, tipc_own_addr(net));
@@ -306,7 +306,7 @@ static struct tipc_member *tipc_group_create_member(struct tipc_group *grp,
struct tipc_member *m;
int ret;
- m = kzalloc(sizeof(*m), GFP_ATOMIC);
+ m = kzalloc_obj(*m, GFP_ATOMIC);
if (!m)
return NULL;
INIT_LIST_HEAD(&m->list);
diff --git a/net/tipc/link.c b/net/tipc/link.c
index 931f55f781a1..49dfc098d89b 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -487,7 +487,7 @@ bool tipc_link_create(struct net *net, char *if_name, int bearer_id,
char self_str[NODE_ID_STR_LEN] = {0,};
struct tipc_link *l;
- l = kzalloc(sizeof(*l), GFP_ATOMIC);
+ l = kzalloc_obj(*l, GFP_ATOMIC);
if (!l)
return false;
*link = l;
diff --git a/net/tipc/monitor.c b/net/tipc/monitor.c
index 572b79bf76ce..a94b9b36a700 100644
--- a/net/tipc/monitor.c
+++ b/net/tipc/monitor.c
@@ -393,7 +393,7 @@ static bool tipc_mon_add_peer(struct tipc_monitor *mon, u32 addr,
struct tipc_peer *self = mon->self;
struct tipc_peer *cur, *prev, *p;
- p = kzalloc(sizeof(*p), GFP_ATOMIC);
+ p = kzalloc_obj(*p, GFP_ATOMIC);
*peer = p;
if (!p)
return false;
@@ -654,9 +654,9 @@ int tipc_mon_create(struct net *net, int bearer_id)
if (tn->monitors[bearer_id])
return 0;
- mon = kzalloc(sizeof(*mon), GFP_ATOMIC);
- self = kzalloc(sizeof(*self), GFP_ATOMIC);
- dom = kzalloc(sizeof(*dom), GFP_ATOMIC);
+ mon = kzalloc_obj(*mon, GFP_ATOMIC);
+ self = kzalloc_obj(*self, GFP_ATOMIC);
+ dom = kzalloc_obj(*dom, GFP_ATOMIC);
if (!mon || !self || !dom) {
kfree(mon);
kfree(self);
diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c
index e74940eab3a4..ec0ac85ca70b 100644
--- a/net/tipc/name_table.c
+++ b/net/tipc/name_table.c
@@ -230,7 +230,7 @@ static struct publication *tipc_publ_create(struct tipc_uaddr *ua,
struct tipc_socket_addr *sk,
u32 key)
{
- struct publication *p = kzalloc(sizeof(*p), GFP_ATOMIC);
+ struct publication *p = kzalloc_obj(*p, GFP_ATOMIC);
if (!p)
return NULL;
@@ -261,7 +261,7 @@ static struct tipc_service *tipc_service_create(struct net *net,
struct tipc_service *service;
struct hlist_head *hd;
- service = kzalloc(sizeof(*service), GFP_ATOMIC);
+ service = kzalloc_obj(*service, GFP_ATOMIC);
if (!service) {
pr_warn("Service creation failed, no memory\n");
return NULL;
@@ -314,7 +314,7 @@ static struct service_range *tipc_service_create_range(struct tipc_service *sc,
else
n = &parent->rb_right;
}
- sr = kzalloc(sizeof(*sr), GFP_ATOMIC);
+ sr = kzalloc_obj(*sr, GFP_ATOMIC);
if (!sr)
return NULL;
sr->lower = lower;
@@ -888,7 +888,7 @@ int tipc_nametbl_init(struct net *net)
struct name_table *nt;
int i;
- nt = kzalloc(sizeof(*nt), GFP_KERNEL);
+ nt = kzalloc_obj(*nt, GFP_KERNEL);
if (!nt)
return -ENOMEM;
@@ -1156,7 +1156,7 @@ bool tipc_dest_push(struct list_head *l, u32 node, u32 port)
if (tipc_dest_find(l, node, port))
return false;
- dst = kmalloc(sizeof(*dst), GFP_ATOMIC);
+ dst = kmalloc_obj(*dst, GFP_ATOMIC);
if (unlikely(!dst))
return false;
dst->node = node;
diff --git a/net/tipc/netlink_compat.c b/net/tipc/netlink_compat.c
index 079aebb16ed8..f64f03ab4933 100644
--- a/net/tipc/netlink_compat.c
+++ b/net/tipc/netlink_compat.c
@@ -202,8 +202,8 @@ static int __tipc_nl_compat_dumpit(struct tipc_nl_compat_cmd_dump *cmd,
return -ENOMEM;
}
- attrbuf = kcalloc(tipc_genl_family.maxattr + 1,
- sizeof(struct nlattr *), GFP_KERNEL);
+ attrbuf = kzalloc_objs(struct nlattr *, tipc_genl_family.maxattr + 1,
+ GFP_KERNEL);
if (!attrbuf) {
err = -ENOMEM;
goto err_out;
@@ -338,9 +338,8 @@ static int __tipc_nl_compat_doit(struct tipc_nl_compat_cmd_doit *cmd,
if (!trans_buf)
return -ENOMEM;
- attrbuf = kmalloc_array(tipc_genl_family.maxattr + 1,
- sizeof(struct nlattr *),
- GFP_KERNEL);
+ attrbuf = kmalloc_objs(struct nlattr *, tipc_genl_family.maxattr + 1,
+ GFP_KERNEL);
if (!attrbuf) {
err = -ENOMEM;
goto trans_out;
diff --git a/net/tipc/node.c b/net/tipc/node.c
index a07fb073368c..af442a5ef8f3 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -535,7 +535,7 @@ update:
goto exit;
}
- n = kzalloc(sizeof(*n), GFP_ATOMIC);
+ n = kzalloc_obj(*n, GFP_ATOMIC);
if (!n) {
pr_warn("Node creation failed, no memory\n");
goto exit;
@@ -703,7 +703,7 @@ int tipc_node_add_conn(struct net *net, u32 dnode, u32 port, u32 peer_port)
pr_warn("Connecting sock to node 0x%x failed\n", dnode);
return -EHOSTUNREACH;
}
- conn = kmalloc(sizeof(*conn), GFP_ATOMIC);
+ conn = kmalloc_obj(*conn, GFP_ATOMIC);
if (!conn) {
err = -EHOSTUNREACH;
goto exit;
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 817b07d95a91..d52f700b5493 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -3595,7 +3595,7 @@ int __tipc_dump_start(struct netlink_callback *cb, struct net *net)
struct tipc_net *tn = tipc_net(net);
if (!iter) {
- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
+ iter = kmalloc_obj(*iter, GFP_KERNEL);
if (!iter)
return -ENOMEM;
diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
index f8490d94e323..352d304c3acd 100644
--- a/net/tipc/subscr.c
+++ b/net/tipc/subscr.c
@@ -143,7 +143,7 @@ struct tipc_subscription *tipc_sub_subscribe(struct net *net,
pr_warn("Subscription rejected, illegal request\n");
return NULL;
}
- sub = kmalloc(sizeof(*sub), GFP_ATOMIC);
+ sub = kmalloc_obj(*sub, GFP_ATOMIC);
if (!sub) {
pr_warn("Subscription rejected, no memory\n");
return NULL;
diff --git a/net/tipc/topsrv.c b/net/tipc/topsrv.c
index aad7f96b6009..af530c9ed840 100644
--- a/net/tipc/topsrv.c
+++ b/net/tipc/topsrv.c
@@ -182,7 +182,7 @@ static struct tipc_conn *tipc_conn_alloc(struct tipc_topsrv *s, struct socket *s
struct tipc_conn *con;
int ret;
- con = kzalloc(sizeof(*con), GFP_ATOMIC);
+ con = kzalloc_obj(*con, GFP_ATOMIC);
if (!con)
return ERR_PTR(-ENOMEM);
@@ -325,7 +325,7 @@ void tipc_topsrv_queue_evt(struct net *net, int conid,
if (!connected(con))
goto err;
- e = kmalloc(sizeof(*e), GFP_ATOMIC);
+ e = kmalloc_obj(*e, GFP_ATOMIC);
if (!e)
goto err;
e->inactive = (event == TIPC_SUBSCR_TIMEOUT);
@@ -661,7 +661,7 @@ static int tipc_topsrv_start(struct net *net)
struct tipc_topsrv *srv;
int ret;
- srv = kzalloc(sizeof(*srv), GFP_ATOMIC);
+ srv = kzalloc_obj(*srv, GFP_ATOMIC);
if (!srv)
return -ENOMEM;
diff --git a/net/tipc/udp_media.c b/net/tipc/udp_media.c
index b85ab0fb3b8c..2b8e385d1e51 100644
--- a/net/tipc/udp_media.c
+++ b/net/tipc/udp_media.c
@@ -309,7 +309,7 @@ static int tipc_udp_rcast_add(struct tipc_bearer *b,
if (!ub)
return -ENODEV;
- rcast = kmalloc(sizeof(*rcast), GFP_ATOMIC);
+ rcast = kmalloc_obj(*rcast, GFP_ATOMIC);
if (!rcast)
return -ENOMEM;
@@ -675,7 +675,7 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b,
struct net_device *dev;
int rmcast = 0;
- ub = kzalloc(sizeof(*ub), GFP_ATOMIC);
+ ub = kzalloc_obj(*ub, GFP_ATOMIC);
if (!ub)
return -ENOMEM;