summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorKees Cook <kees+treewide@kernel.org>2026-09-02 15:31:14 -0700
committerKees Cook <kees@kernel.org>2026-09-04 21:37:00 -0700
commit3a2c4d55e32ad65efebdb6de44eef3bfa08bb49d (patch)
treec65086f9bdcd48c6360fb7cb4598bca084da1f32 /net
parent90feea391c64fc43bf44184fcf2b243ab991ce47 (diff)
treewide: refresh kmalloc_obj() conversions
This is another run of the Coccinelle script for converting kmalloc() family of allocations to kmalloc_obj() via the existing rules in scripts/coccinelle/api/kmalloc_objs.cocci This catches both the set of kmalloc() uses added since the first kmalloc_obj() conversions in v7.0 and adds a large group missed in the first pass due to Coccinelle not interacting well with the cleanup.h scoped_...() family of macros[1]. I worked around this with spatch's "--macro-file" argument to a file with all the scoped_...() macros mapped to Coccinelle's YACFE_ITERATOR[2] as that was the closest viable control flow indicator I could find. Build tested allmodconfig on x86, arm64, arm, loongarch, mips, powerpc, riscv, and s390 with no new warnings. Link: https://lore.kernel.org/lkml/202609021314.8A9C0B8@keescook/ [1] Link: https://github.com/coccinelle/coccinelle/blob/master/standard.h [2] Signed-off-by: Kees Cook <kees+treewide@kernel.org>
Diffstat (limited to 'net')
-rw-r--r--net/batman-adv/hard-interface.c2
-rw-r--r--net/bluetooth/hci_sync.c3
-rw-r--r--net/devlink/netlink.c2
-rw-r--r--net/devlink/param.c7
-rw-r--r--net/ipv4/tcp_ipv4.c4
-rw-r--r--net/mac80211/nan.c3
-rw-r--r--net/mctp/test/route-test.c2
-rw-r--r--net/mctp/test/utils.c2
-rw-r--r--net/netfilter/nf_tables_api.c2
-rw-r--r--net/netfilter/nfnetlink_cttimeout.c2
-rw-r--r--net/rds/info.c2
-rw-r--r--net/rxrpc/key.c2
-rw-r--r--net/sched/act_gate.c4
-rw-r--r--net/sched/act_tunnel_key.c2
-rw-r--r--net/sunrpc/auth_gss/gss_krb5_crypto.c5
-rw-r--r--net/sunrpc/svcauth_unix.c4
-rw-r--r--net/sunrpc/xdr.c3
-rw-r--r--net/unix/af_unix.c4
-rw-r--r--net/wireless/core.c5
-rw-r--r--net/wireless/nl80211.c9
20 files changed, 30 insertions, 39 deletions
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index e7ad295504e4..c5bc60d16e40 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -981,7 +981,7 @@ batadv_wifi_net_device_insert(struct net_device *net_dev, u32 wifi_flags)
ASSERT_RTNL();
- device_state = kzalloc_obj(*device_state, GFP_KERNEL);
+ device_state = kzalloc_obj(*device_state);
if (!device_state)
return -ENOMEM;
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index ffd7b37e7401..3f121099eb22 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -6423,8 +6423,7 @@ static int hci_update_event_filter_sync(struct hci_dev *hdev)
goto update_scan;
}
- accept_list = kmalloc_array(num_entries, sizeof(*accept_list),
- GFP_KERNEL);
+ accept_list = kmalloc_objs(*accept_list, num_entries);
if (!accept_list) {
hci_dev_unlock(hdev);
return -ENOMEM;
diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c
index 300580c1a217..a8eda727bff1 100644
--- a/net/devlink/netlink.c
+++ b/net/devlink/netlink.c
@@ -251,7 +251,7 @@ devlink_get_parent_from_attrs_lock(struct net *net, struct nlattr **attrs)
if (!attrs[DEVLINK_ATTR_PARENT_DEV])
return ERR_PTR(-EINVAL);
- tb = kcalloc(maxtype + 1, sizeof(*tb), GFP_KERNEL);
+ tb = kzalloc_objs(*tb, maxtype + 1);
if (!tb)
return ERR_PTR(-ENOMEM);
diff --git a/net/devlink/param.c b/net/devlink/param.c
index 8ca0f3ed646c..95ac9db8c993 100644
--- a/net/devlink/param.c
+++ b/net/devlink/param.c
@@ -330,13 +330,12 @@ static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink,
int err;
int i;
- default_value = kcalloc(DEVLINK_PARAM_CMODE_MAX + 1,
- sizeof(*default_value), GFP_KERNEL);
+ default_value = kzalloc_objs(*default_value,
+ DEVLINK_PARAM_CMODE_MAX + 1);
if (!default_value)
return -ENOMEM;
- param_value = kcalloc(DEVLINK_PARAM_CMODE_MAX + 1,
- sizeof(*param_value), GFP_KERNEL);
+ param_value = kzalloc_objs(*param_value, DEVLINK_PARAM_CMODE_MAX + 1);
if (!param_value) {
kfree(default_value);
return -ENOMEM;
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 9f053eb8b46e..04dbb2babbcd 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -2931,8 +2931,8 @@ static int bpf_iter_tcp_realloc_batch(struct bpf_tcp_iter_state *iter,
{
union bpf_tcp_iter_batch_item *new_batch;
- new_batch = kvmalloc_array(new_batch_sz, sizeof(*new_batch),
- flags | __GFP_NOWARN);
+ new_batch = kvmalloc_objs(*new_batch, new_batch_sz,
+ flags | __GFP_NOWARN);
if (!new_batch)
return -ENOMEM;
diff --git a/net/mac80211/nan.c b/net/mac80211/nan.c
index 19e08661be43..c7769da9617b 100644
--- a/net/mac80211/nan.c
+++ b/net/mac80211/nan.c
@@ -659,8 +659,7 @@ int ieee80211_nan_set_peer_sched(struct ieee80211_sub_if_data *sdata,
if (!sta)
return -ENOENT;
- new_sched = kzalloc(struct_size(new_sched, channels, sched->n_channels),
- GFP_KERNEL);
+ new_sched = kzalloc_flex(*new_sched, channels, sched->n_channels);
if (!new_sched)
return -ENOMEM;
diff --git a/net/mctp/test/route-test.c b/net/mctp/test/route-test.c
index c92e3abb40d7..f05f75bf93e0 100644
--- a/net/mctp/test/route-test.c
+++ b/net/mctp/test/route-test.c
@@ -193,7 +193,7 @@ static void __mctp_route_test_init(struct kunit *test,
if (netid != MCTP_NET_ANY)
WRITE_ONCE(dev->mdev->net, netid);
- dev->mdev->addrs = kmalloc_objs(u8, 1, GFP_KERNEL);
+ dev->mdev->addrs = kmalloc_objs(u8, 1);
dev->mdev->num_addrs = 1;
dev->mdev->addrs[0] = 8;
diff --git a/net/mctp/test/utils.c b/net/mctp/test/utils.c
index 6eef8d485c25..6b131084a249 100644
--- a/net/mctp/test/utils.c
+++ b/net/mctp/test/utils.c
@@ -88,7 +88,7 @@ struct mctp_test_dev *mctp_test_create_dev_with_addr(mctp_eid_t addr)
if (!dev)
return NULL;
- dev->mdev->addrs = kmalloc_objs(u8, 1, GFP_KERNEL);
+ dev->mdev->addrs = kmalloc_objs(u8, 1);
if (!dev->mdev->addrs) {
mctp_test_destroy_dev(dev);
return NULL;
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 765a92fa90d6..31fbd5a28937 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -3215,7 +3215,7 @@ static int nft_trans_delhook(struct nft_hook *hook,
{
struct nft_trans_hook *trans_hook;
- trans_hook = kmalloc_obj(*trans_hook, GFP_KERNEL);
+ trans_hook = kmalloc_obj(*trans_hook);
if (!trans_hook)
return -ENOMEM;
diff --git a/net/netfilter/nfnetlink_cttimeout.c b/net/netfilter/nfnetlink_cttimeout.c
index 66c2016f6049..f43bf768b31c 100644
--- a/net/netfilter/nfnetlink_cttimeout.c
+++ b/net/netfilter/nfnetlink_cttimeout.c
@@ -150,7 +150,7 @@ static int cttimeout_new_timeout(struct sk_buff *skb,
goto err_proto_put;
}
- timeout = kzalloc(sizeof(*timeout), GFP_KERNEL);
+ timeout = kzalloc_obj(*timeout);
if (timeout == NULL) {
ret = -ENOMEM;
goto err_proto_put;
diff --git a/net/rds/info.c b/net/rds/info.c
index 31e7ad108459..a57f81a05c87 100644
--- a/net/rds/info.c
+++ b/net/rds/info.c
@@ -205,7 +205,7 @@ int rds_info_getsockopt(struct socket *sock, int optname, sockopt_t *opt)
* iterator code to allocate and hand it back.
*/
npages = iov_iter_npages(&opt->iter_out, INT_MAX);
- pages = kvmalloc_array(npages, sizeof(*pages), GFP_KERNEL);
+ pages = kvmalloc_objs(*pages, npages);
if (!pages) {
ret = -ENOMEM;
goto out;
diff --git a/net/rxrpc/key.c b/net/rxrpc/key.c
index a0aa78d89289..cbd26da44951 100644
--- a/net/rxrpc/key.c
+++ b/net/rxrpc/key.c
@@ -210,7 +210,7 @@ static int rxrpc_preparse_xdr_yfs_rxgk(struct key_preparsed_payload *prep,
if (!token)
goto nomem;
- token->rxgk = kzalloc(struct_size_t(struct rxgk_key, _key, raw_keylen), GFP_KERNEL);
+ token->rxgk = kzalloc_flex(struct rxgk_key, _key, raw_keylen);
if (!token->rxgk)
goto nomem_token;
diff --git a/net/sched/act_gate.c b/net/sched/act_gate.c
index fdbfcaa3e2ab..5d228a402204 100644
--- a/net/sched/act_gate.c
+++ b/net/sched/act_gate.c
@@ -240,7 +240,7 @@ static int tcf_gate_copy_entries(struct tcf_gate_params *dst,
list_for_each_entry(entry, &src->entries, list) {
struct tcfg_gate_entry *new;
- new = kzalloc(sizeof(*new), GFP_ATOMIC);
+ new = kzalloc_obj(*new, GFP_ATOMIC);
if (!new) {
NL_SET_ERR_MSG(extack, "Not enough memory for entry");
return -ENOMEM;
@@ -415,7 +415,7 @@ static int tcf_gate_init(struct net *net, struct nlattr *nla,
if (err < 0)
goto release_idr;
- p = kzalloc(sizeof(*p), GFP_KERNEL);
+ p = kzalloc_obj(*p);
if (!p) {
err = -ENOMEM;
goto chain_put;
diff --git a/net/sched/act_tunnel_key.c b/net/sched/act_tunnel_key.c
index ff401ace4f3d..503834853306 100644
--- a/net/sched/act_tunnel_key.c
+++ b/net/sched/act_tunnel_key.c
@@ -526,7 +526,7 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,
}
t = to_tunnel_key(*a);
- params_new = kzalloc(sizeof(*params_new), GFP_KERNEL);
+ params_new = kzalloc_obj(*params_new);
if (unlikely(!params_new)) {
NL_SET_ERR_MSG(extack, "Cannot allocate tunnel key parameters");
ret = -ENOMEM;
diff --git a/net/sunrpc/auth_gss/gss_krb5_crypto.c b/net/sunrpc/auth_gss/gss_krb5_crypto.c
index cf461ebcdde5..09a7c97e87da 100644
--- a/net/sunrpc/auth_gss/gss_krb5_crypto.c
+++ b/net/sunrpc/auth_gss/gss_krb5_crypto.c
@@ -282,9 +282,8 @@ int gss_krb5_mic_build_sg(const struct xdr_buf *body,
unsigned int overflow_nents =
nsg - XDR_BUF_TO_SG_NENTS + 1;
- *sg_overflow = kmalloc_array(overflow_nents,
- sizeof(**sg_overflow),
- GFP_NOFS);
+ *sg_overflow = kmalloc_objs(**sg_overflow, overflow_nents,
+ GFP_NOFS);
if (!*sg_overflow)
return -ENOMEM;
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
index aebd97e7f66c..31a1bc60a5f6 100644
--- a/net/sunrpc/svcauth_unix.c
+++ b/net/sunrpc/svcauth_unix.c
@@ -625,7 +625,7 @@ int sunrpc_nl_unix_gid_get_reqs_dumpit(struct sk_buff *skb,
if (!cnt)
return 0;
- items = kcalloc(cnt, sizeof(*items), GFP_KERNEL);
+ items = kzalloc_objs(*items, cnt);
seqnos = kcalloc(cnt, sizeof(*seqnos), GFP_KERNEL);
if (!items || !seqnos) {
ret = -ENOMEM;
@@ -1326,7 +1326,7 @@ int sunrpc_nl_ip_map_get_reqs_dumpit(struct sk_buff *skb,
if (!cnt)
return 0;
- items = kcalloc(cnt, sizeof(*items), GFP_KERNEL);
+ items = kzalloc_objs(*items, cnt);
seqnos = kcalloc(cnt, sizeof(*seqnos), GFP_KERNEL);
if (!items || !seqnos) {
ret = -ENOMEM;
diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
index cb2ef428651f..c42fd338c607 100644
--- a/net/sunrpc/xdr.c
+++ b/net/sunrpc/xdr.c
@@ -371,8 +371,7 @@ int xdr_buf_to_sg_alloc(const struct xdr_buf *buf, unsigned int offset,
unsigned int overflow_nents = nsg - sg_head_nents + 1;
struct scatterlist *overflow;
- overflow = kmalloc_array(overflow_nents, sizeof(*overflow),
- gfp);
+ overflow = kmalloc_objs(*overflow, overflow_nents, gfp);
if (!overflow)
return -ENOMEM;
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 13f9926bf205..79c3921c583c 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -3667,8 +3667,8 @@ static int bpf_iter_unix_realloc_batch(struct bpf_unix_iter_state *iter,
{
struct sock **new_batch;
- new_batch = kvmalloc_array(new_batch_sz, sizeof(*new_batch),
- GFP_USER | __GFP_NOWARN);
+ new_batch = kvmalloc_objs(*new_batch, new_batch_sz,
+ GFP_USER | __GFP_NOWARN);
if (!new_batch)
return -ENOMEM;
diff --git a/net/wireless/core.c b/net/wireless/core.c
index d13310fef691..3032993ba5dc 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -311,9 +311,8 @@ int cfg80211_nan_set_local_schedule(struct cfg80211_registered_device *rdev,
if (!sched->n_channels)
return 0;
- wdev->u.nan.chandefs = kcalloc(sched->n_channels,
- sizeof(*wdev->u.nan.chandefs),
- GFP_KERNEL);
+ wdev->u.nan.chandefs = kzalloc_objs(*wdev->u.nan.chandefs,
+ sched->n_channels);
if (!wdev->u.nan.chandefs)
return -ENOMEM;
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 44f2bad08670..899b6374c550 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -17330,8 +17330,7 @@ static int nl80211_parse_nan_channel(struct cfg80211_registered_device *rdev,
u8 n_rx_nss;
int ret;
- channel_parsed = kcalloc(NL80211_ATTR_MAX + 1, sizeof(*channel_parsed),
- GFP_KERNEL);
+ channel_parsed = kzalloc_objs(*channel_parsed, NL80211_ATTR_MAX + 1);
if (!channel_parsed)
return -ENOMEM;
@@ -17554,8 +17553,7 @@ static int nl80211_nan_set_peer_sched(struct sk_buff *skb,
}
if (n_channels) {
- nan_channels = kcalloc(n_channels, sizeof(*nan_channels),
- GFP_KERNEL);
+ nan_channels = kzalloc_objs(*nan_channels, n_channels);
if (!nan_channels)
return -ENOMEM;
}
@@ -17693,8 +17691,7 @@ static int nl80211_nan_set_local_sched(struct sk_buff *skb,
info->nlhdr, GENL_HDRLEN, rem)
n_channels++;
- sched = kzalloc(struct_size(sched, nan_channels, n_channels),
- GFP_KERNEL);
+ sched = kzalloc_flex(*sched, nan_channels, n_channels);
if (!sched)
return -ENOMEM;