summaryrefslogtreecommitdiff
path: root/drivers/net/wireguard
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/wireguard
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/wireguard')
-rw-r--r--drivers/net/wireguard/noise.c2
-rw-r--r--drivers/net/wireguard/peerlookup.c4
-rw-r--r--drivers/net/wireguard/ratelimiter.c4
-rw-r--r--drivers/net/wireguard/selftest/allowedips.c10
-rw-r--r--drivers/net/wireguard/selftest/counter.c2
5 files changed, 11 insertions, 11 deletions
diff --git a/drivers/net/wireguard/noise.c b/drivers/net/wireguard/noise.c
index 1fe8468f0bef..994b7c6f0613 100644
--- a/drivers/net/wireguard/noise.c
+++ b/drivers/net/wireguard/noise.c
@@ -97,7 +97,7 @@ void wg_noise_handshake_clear(struct noise_handshake *handshake)
static struct noise_keypair *keypair_create(struct wg_peer *peer)
{
- struct noise_keypair *keypair = kzalloc(sizeof(*keypair), GFP_KERNEL);
+ struct noise_keypair *keypair = kzalloc_obj(*keypair, GFP_KERNEL);
if (unlikely(!keypair))
return NULL;
diff --git a/drivers/net/wireguard/peerlookup.c b/drivers/net/wireguard/peerlookup.c
index f2783aa7a88f..5ae4e6c5e7c9 100644
--- a/drivers/net/wireguard/peerlookup.c
+++ b/drivers/net/wireguard/peerlookup.c
@@ -21,7 +21,7 @@ static struct hlist_head *pubkey_bucket(struct pubkey_hashtable *table,
struct pubkey_hashtable *wg_pubkey_hashtable_alloc(void)
{
- struct pubkey_hashtable *table = kvmalloc(sizeof(*table), GFP_KERNEL);
+ struct pubkey_hashtable *table = kvmalloc_obj(*table, GFP_KERNEL);
if (!table)
return NULL;
@@ -82,7 +82,7 @@ static struct hlist_head *index_bucket(struct index_hashtable *table,
struct index_hashtable *wg_index_hashtable_alloc(void)
{
- struct index_hashtable *table = kvmalloc(sizeof(*table), GFP_KERNEL);
+ struct index_hashtable *table = kvmalloc_obj(*table, GFP_KERNEL);
if (!table)
return NULL;
diff --git a/drivers/net/wireguard/ratelimiter.c b/drivers/net/wireguard/ratelimiter.c
index dd55e5c26f46..13d532a44294 100644
--- a/drivers/net/wireguard/ratelimiter.c
+++ b/drivers/net/wireguard/ratelimiter.c
@@ -176,12 +176,12 @@ int wg_ratelimiter_init(void)
(1U << 14) / sizeof(struct hlist_head)));
max_entries = table_size * 8;
- table_v4 = kvcalloc(table_size, sizeof(*table_v4), GFP_KERNEL);
+ table_v4 = kvzalloc_objs(*table_v4, table_size, GFP_KERNEL);
if (unlikely(!table_v4))
goto err_kmemcache;
#if IS_ENABLED(CONFIG_IPV6)
- table_v6 = kvcalloc(table_size, sizeof(*table_v6), GFP_KERNEL);
+ table_v6 = kvzalloc_objs(*table_v6, table_size, GFP_KERNEL);
if (unlikely(!table_v6)) {
kvfree(table_v4);
goto err_kmemcache;
diff --git a/drivers/net/wireguard/selftest/allowedips.c b/drivers/net/wireguard/selftest/allowedips.c
index 41837efa70cb..6c7c79e39ad4 100644
--- a/drivers/net/wireguard/selftest/allowedips.c
+++ b/drivers/net/wireguard/selftest/allowedips.c
@@ -181,7 +181,7 @@ static __init int
horrible_allowedips_insert_v4(struct horrible_allowedips *table,
struct in_addr *ip, u8 cidr, void *value)
{
- struct horrible_allowedips_node *node = kzalloc(sizeof(*node), GFP_KERNEL);
+ struct horrible_allowedips_node *node = kzalloc_obj(*node, GFP_KERNEL);
if (unlikely(!node))
return -ENOMEM;
@@ -198,7 +198,7 @@ static __init int
horrible_allowedips_insert_v6(struct horrible_allowedips *table,
struct in6_addr *ip, u8 cidr, void *value)
{
- struct horrible_allowedips_node *node = kzalloc(sizeof(*node), GFP_KERNEL);
+ struct horrible_allowedips_node *node = kzalloc_obj(*node, GFP_KERNEL);
if (unlikely(!node))
return -ENOMEM;
@@ -266,13 +266,13 @@ static __init bool randomized_test(void)
wg_allowedips_init(&t);
horrible_allowedips_init(&h);
- peers = kcalloc(NUM_PEERS, sizeof(*peers), GFP_KERNEL);
+ peers = kzalloc_objs(*peers, NUM_PEERS, GFP_KERNEL);
if (unlikely(!peers)) {
pr_err("allowedips random self-test malloc: FAIL\n");
goto free;
}
for (i = 0; i < NUM_PEERS; ++i) {
- peers[i] = kzalloc(sizeof(*peers[i]), GFP_KERNEL);
+ peers[i] = kzalloc_obj(*peers[i], GFP_KERNEL);
if (unlikely(!peers[i])) {
pr_err("allowedips random self-test malloc: FAIL\n");
goto free;
@@ -447,7 +447,7 @@ static __init inline struct in6_addr *ip6(u32 a, u32 b, u32 c, u32 d)
static __init struct wg_peer *init_peer(void)
{
- struct wg_peer *peer = kzalloc(sizeof(*peer), GFP_KERNEL);
+ struct wg_peer *peer = kzalloc_obj(*peer, GFP_KERNEL);
if (!peer)
return NULL;
diff --git a/drivers/net/wireguard/selftest/counter.c b/drivers/net/wireguard/selftest/counter.c
index ec3c156bf91b..13c5535a1fd6 100644
--- a/drivers/net/wireguard/selftest/counter.c
+++ b/drivers/net/wireguard/selftest/counter.c
@@ -10,7 +10,7 @@ bool __init wg_packet_counter_selftest(void)
unsigned int test_num = 0, i;
bool success = true;
- counter = kmalloc(sizeof(*counter), GFP_KERNEL);
+ counter = kmalloc_obj(*counter, GFP_KERNEL);
if (unlikely(!counter)) {
pr_err("nonce counter self-test malloc: FAIL\n");
return false;