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 /net/sctp | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
| download | lwn-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/sctp')
| -rw-r--r-- | net/sctp/associola.c | 2 | ||||
| -rw-r--r-- | net/sctp/auth.c | 6 | ||||
| -rw-r--r-- | net/sctp/bind_addr.c | 2 | ||||
| -rw-r--r-- | net/sctp/chunk.c | 2 | ||||
| -rw-r--r-- | net/sctp/endpointola.c | 2 | ||||
| -rw-r--r-- | net/sctp/ipv6.c | 4 | ||||
| -rw-r--r-- | net/sctp/protocol.c | 6 | ||||
| -rw-r--r-- | net/sctp/socket.c | 2 | ||||
| -rw-r--r-- | net/sctp/stream.c | 2 | ||||
| -rw-r--r-- | net/sctp/stream_sched_prio.c | 2 | ||||
| -rw-r--r-- | net/sctp/transport.c | 2 |
11 files changed, 16 insertions, 16 deletions
diff --git a/net/sctp/associola.c b/net/sctp/associola.c index 5793d71852b8..62d3cc155809 100644 --- a/net/sctp/associola.c +++ b/net/sctp/associola.c @@ -289,7 +289,7 @@ struct sctp_association *sctp_association_new(const struct sctp_endpoint *ep, { struct sctp_association *asoc; - asoc = kzalloc(sizeof(*asoc), gfp); + asoc = kzalloc_obj(*asoc, gfp); if (!asoc) goto fail; diff --git a/net/sctp/auth.c b/net/sctp/auth.c index 82aad477590e..be9782760f50 100644 --- a/net/sctp/auth.c +++ b/net/sctp/auth.c @@ -82,7 +82,7 @@ struct sctp_shared_key *sctp_auth_shkey_create(__u16 key_id, gfp_t gfp) struct sctp_shared_key *new; /* Allocate the shared key container */ - new = kzalloc(sizeof(struct sctp_shared_key), gfp); + new = kzalloc_obj(struct sctp_shared_key, gfp); if (!new) return NULL; @@ -931,8 +931,8 @@ int sctp_auth_init(struct sctp_endpoint *ep, gfp_t gfp) if (!ep->auth_hmacs_list) { struct sctp_hmac_algo_param *auth_hmacs; - auth_hmacs = kzalloc(struct_size(auth_hmacs, hmac_ids, - SCTP_AUTH_NUM_HMACS), gfp); + auth_hmacs = kzalloc_flex(*auth_hmacs, hmac_ids, + SCTP_AUTH_NUM_HMACS, gfp); if (!auth_hmacs) goto nomem; /* Initialize the HMACS parameter. diff --git a/net/sctp/bind_addr.c b/net/sctp/bind_addr.c index 6b95d3ba8fe1..75e3e61d494e 100644 --- a/net/sctp/bind_addr.c +++ b/net/sctp/bind_addr.c @@ -147,7 +147,7 @@ int sctp_add_bind_addr(struct sctp_bind_addr *bp, union sctp_addr *new, struct sctp_sockaddr_entry *addr; /* Add the address to the bind address list. */ - addr = kzalloc(sizeof(*addr), gfp); + addr = kzalloc_obj(*addr, gfp); if (!addr) return -ENOMEM; diff --git a/net/sctp/chunk.c b/net/sctp/chunk.c index c655b571ca01..5b889e89e9f2 100644 --- a/net/sctp/chunk.c +++ b/net/sctp/chunk.c @@ -47,7 +47,7 @@ static void sctp_datamsg_init(struct sctp_datamsg *msg) static struct sctp_datamsg *sctp_datamsg_new(gfp_t gfp) { struct sctp_datamsg *msg; - msg = kmalloc(sizeof(struct sctp_datamsg), gfp); + msg = kmalloc_obj(struct sctp_datamsg, gfp); if (msg) { sctp_datamsg_init(msg); SCTP_DBG_OBJCNT_INC(datamsg); diff --git a/net/sctp/endpointola.c b/net/sctp/endpointola.c index 31e989dfe846..8d342b514142 100644 --- a/net/sctp/endpointola.c +++ b/net/sctp/endpointola.c @@ -135,7 +135,7 @@ struct sctp_endpoint *sctp_endpoint_new(struct sock *sk, gfp_t gfp) struct sctp_endpoint *ep; /* Build a local endpoint. */ - ep = kzalloc(sizeof(*ep), gfp); + ep = kzalloc_obj(*ep, gfp); if (!ep) goto fail; diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c index 531cb0690007..53a5c027f8e3 100644 --- a/net/sctp/ipv6.c +++ b/net/sctp/ipv6.c @@ -83,7 +83,7 @@ static int sctp_inet6addr_event(struct notifier_block *this, unsigned long ev, switch (ev) { case NETDEV_UP: - addr = kzalloc(sizeof(*addr), GFP_ATOMIC); + addr = kzalloc_obj(*addr, GFP_ATOMIC); if (addr) { addr->a.v6.sin6_family = AF_INET6; addr->a.v6.sin6_addr = ifa->addr; @@ -471,7 +471,7 @@ static void sctp_v6_copy_addrlist(struct list_head *addrlist, read_lock_bh(&in6_dev->lock); list_for_each_entry(ifp, &in6_dev->addr_list, if_list) { /* Add the address to the local list. */ - addr = kzalloc(sizeof(*addr), GFP_ATOMIC); + addr = kzalloc_obj(*addr, GFP_ATOMIC); if (addr) { addr->a.v6.sin6_family = AF_INET6; addr->a.v6.sin6_addr = ifp->addr; diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c index 2c3398f75d76..0723cbdbc366 100644 --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c @@ -86,7 +86,7 @@ static void sctp_v4_copy_addrlist(struct list_head *addrlist, in_dev_for_each_ifa_rcu(ifa, in_dev) { /* Add the address to the local list. */ - addr = kzalloc(sizeof(*addr), GFP_ATOMIC); + addr = kzalloc_obj(*addr, GFP_ATOMIC); if (addr) { addr->a.v4.sin_family = AF_INET; addr->a.v4.sin_addr.s_addr = ifa->ifa_local; @@ -774,7 +774,7 @@ static int sctp_inetaddr_event(struct notifier_block *this, unsigned long ev, switch (ev) { case NETDEV_UP: - addr = kzalloc(sizeof(*addr), GFP_ATOMIC); + addr = kzalloc_obj(*addr, GFP_ATOMIC); if (addr) { addr->a.v4.sin_family = AF_INET; addr->a.v4.sin_addr.s_addr = ifa->ifa_local; @@ -1538,7 +1538,7 @@ static __init int sctp_init(void) /* Allocate and initialize the endpoint hash table. */ sctp_ep_hashsize = 64; sctp_ep_hashtable = - kmalloc_array(64, sizeof(struct sctp_hashbucket), GFP_KERNEL); + kmalloc_objs(struct sctp_hashbucket, 64, GFP_KERNEL); if (!sctp_ep_hashtable) { pr_err("Failed endpoint_hash alloc\n"); status = -ENOMEM; diff --git a/net/sctp/socket.c b/net/sctp/socket.c index 2493a5b1fa3c..05fb00c9c335 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -828,7 +828,7 @@ static int sctp_send_asconf_del_ip(struct sock *sk, if (asoc->asconf_addr_del_pending) continue; asoc->asconf_addr_del_pending = - kzalloc(sizeof(union sctp_addr), GFP_ATOMIC); + kzalloc_obj(union sctp_addr, GFP_ATOMIC); if (asoc->asconf_addr_del_pending == NULL) { retval = -ENOMEM; goto out; diff --git a/net/sctp/stream.c b/net/sctp/stream.c index 0615e4426341..03636bed60ff 100644 --- a/net/sctp/stream.c +++ b/net/sctp/stream.c @@ -166,7 +166,7 @@ int sctp_stream_init_ext(struct sctp_stream *stream, __u16 sid) struct sctp_stream_out_ext *soute; int ret; - soute = kzalloc(sizeof(*soute), GFP_KERNEL); + soute = kzalloc_obj(*soute, GFP_KERNEL); if (!soute) return -ENOMEM; SCTP_SO(stream, sid)->ext = soute; diff --git a/net/sctp/stream_sched_prio.c b/net/sctp/stream_sched_prio.c index fb6c55e5615d..bd4f98db2822 100644 --- a/net/sctp/stream_sched_prio.c +++ b/net/sctp/stream_sched_prio.c @@ -42,7 +42,7 @@ static struct sctp_stream_priorities *sctp_sched_prio_new_head( { struct sctp_stream_priorities *p; - p = kmalloc(sizeof(*p), gfp); + p = kmalloc_obj(*p, gfp); if (!p) return NULL; diff --git a/net/sctp/transport.c b/net/sctp/transport.c index 0c56d9673cc1..6ea55b9fbde4 100644 --- a/net/sctp/transport.c +++ b/net/sctp/transport.c @@ -92,7 +92,7 @@ struct sctp_transport *sctp_transport_new(struct net *net, { struct sctp_transport *transport; - transport = kzalloc(sizeof(*transport), gfp); + transport = kzalloc_obj(*transport, gfp); if (!transport) return NULL; |
