aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-09-04 11:18:09 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2018-09-04 11:18:58 -0600
commit32d43304abbe9a8546a0c453b7f358a359e4467a (patch)
treeab42a47a8ecd2fae1d8ed64c5bc2479ac8d7161f
parentglobal: prefer sizeof(*pointer) when possible (diff)
downloadwireguard-monolithic-historical-32d43304abbe9a8546a0c453b7f358a359e4467a.tar.xz
wireguard-monolithic-historical-32d43304abbe9a8546a0c453b7f358a359e4467a.zip
global: always find OOM unlikely
Suggested-by: Sultan Alsawaf <sultanxda@gmail.com>
-rw-r--r--src/allowedips.c6
-rw-r--r--src/netlink.c6
-rw-r--r--src/peer.c2
-rw-r--r--src/ratelimiter.c6
-rw-r--r--src/selftest/allowedips.h10
-rw-r--r--src/selftest/ratelimiter.h4
6 files changed, 17 insertions, 17 deletions
diff --git a/src/allowedips.c b/src/allowedips.c
index 14f8e13..fab15ad 100644
--- a/src/allowedips.c
+++ b/src/allowedips.c
@@ -255,7 +255,7 @@ static int add(struct allowedips_node __rcu **trie, u8 bits, const u8 *be_key,
if (!rcu_access_pointer(*trie)) {
node = kzalloc(sizeof(*node), GFP_KERNEL);
- if (!node)
+ if (unlikely(!node))
return -ENOMEM;
RCU_INIT_POINTER(node->peer, peer);
copy_and_assign_cidr(node, key, cidr, bits);
@@ -268,7 +268,7 @@ static int add(struct allowedips_node __rcu **trie, u8 bits, const u8 *be_key,
}
newnode = kzalloc(sizeof(*newnode), GFP_KERNEL);
- if (!newnode)
+ if (unlikely(!newnode))
return -ENOMEM;
RCU_INIT_POINTER(newnode->peer, peer);
copy_and_assign_cidr(newnode, key, cidr, bits);
@@ -295,7 +295,7 @@ static int add(struct allowedips_node __rcu **trie, u8 bits, const u8 *be_key,
newnode);
} else {
node = kzalloc(sizeof(*node), GFP_KERNEL);
- if (!node) {
+ if (unlikely(!node)) {
kfree(newnode);
return -ENOMEM;
}
diff --git a/src/netlink.c b/src/netlink.c
index 98848c9..0bd2b97 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -175,9 +175,9 @@ static int get_device_start(struct netlink_callback *cb)
if (ret < 0)
return ret;
- cb->args[2] =
- (long)kzalloc(sizeof(struct allowedips_cursor), GFP_KERNEL);
- if (!cb->args[2])
+ cb->args[2] = (long)kzalloc(sizeof(struct allowedips_cursor),
+ GFP_KERNEL);
+ if (unlikely(!cb->args[2]))
return -ENOMEM;
wg = lookup_interface(attrs, cb->skb);
if (IS_ERR(wg)) {
diff --git a/src/peer.c b/src/peer.c
index e9cbe0c..ca7981c 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -30,7 +30,7 @@ peer_create(struct wireguard_device *wg,
return NULL;
peer = kzalloc(sizeof(*peer), GFP_KERNEL);
- if (!peer)
+ if (unlikely(!peer))
return NULL;
peer->device = wg;
diff --git a/src/ratelimiter.c b/src/ratelimiter.c
index 6c7262a..52381ee 100644
--- a/src/ratelimiter.c
+++ b/src/ratelimiter.c
@@ -133,7 +133,7 @@ bool ratelimiter_allow(struct sk_buff *skb, struct net *net)
goto err_oom;
entry = kmem_cache_alloc(entry_cache, GFP_KERNEL);
- if (!entry)
+ if (unlikely(!entry))
goto err_oom;
entry->net = net;
@@ -174,12 +174,12 @@ int ratelimiter_init(void)
max_entries = table_size * 8;
table_v4 = kvzalloc(table_size * sizeof(*table_v4), GFP_KERNEL);
- if (!table_v4)
+ if (unlikely(!table_v4))
goto err_kmemcache;
#if IS_ENABLED(CONFIG_IPV6)
table_v6 = kvzalloc(table_size * sizeof(*table_v6), GFP_KERNEL);
- if (!table_v6) {
+ if (unlikely(!table_v6)) {
kvfree(table_v4);
goto err_kmemcache;
}
diff --git a/src/selftest/allowedips.h b/src/selftest/allowedips.h
index 6b47fc8..83cfb34 100644
--- a/src/selftest/allowedips.h
+++ b/src/selftest/allowedips.h
@@ -178,7 +178,7 @@ horrible_allowedips_insert_v4(struct horrible_allowedips *table,
{
struct horrible_allowedips_node *node = kzalloc(sizeof(*node), GFP_KERNEL);
- if (!node)
+ if (unlikely(!node))
return -ENOMEM;
node->ip.in = *ip;
node->mask = horrible_cidr_to_mask(cidr);
@@ -194,7 +194,7 @@ horrible_allowedips_insert_v6(struct horrible_allowedips *table,
{
struct horrible_allowedips_node *node = kzalloc(sizeof(*node), GFP_KERNEL);
- if (!node)
+ if (unlikely(!node))
return -ENOMEM;
node->ip.in6 = *ip;
node->mask = horrible_cidr_to_mask(cidr);
@@ -255,13 +255,13 @@ static __init bool randomized_test(void)
horrible_allowedips_init(&h);
peers = kcalloc(NUM_PEERS, sizeof(*peers), GFP_KERNEL);
- if (!peers) {
+ if (unlikely(!peers)) {
pr_info("allowedips random self-test: out of memory\n");
goto free;
}
for (i = 0; i < NUM_PEERS; ++i) {
peers[i] = kzalloc(sizeof(*peers[i]), GFP_KERNEL);
- if (!peers[i]) {
+ if (unlikely(!peers[i])) {
pr_info("allowedips random self-test: out of memory\n");
goto free;
}
@@ -455,7 +455,7 @@ static __init int walk_callback(void *ctx, const u8 *ip, u8 cidr, int family)
#define init_peer(name) do { \
name = kzalloc(sizeof(*name), GFP_KERNEL); \
- if (!name) { \
+ if (unlikely(!name)) { \
pr_info("allowedips self-test: out of memory\n"); \
goto free; \
} \
diff --git a/src/selftest/ratelimiter.h b/src/selftest/ratelimiter.h
index 1f2b697..f9f9996 100644
--- a/src/selftest/ratelimiter.h
+++ b/src/selftest/ratelimiter.h
@@ -59,7 +59,7 @@ bool __init ratelimiter_selftest(void)
++test;
skb4 = alloc_skb(sizeof(struct iphdr), GFP_KERNEL);
- if (!skb4)
+ if (unlikely(!skb4))
goto err_nofree;
skb4->protocol = htons(ETH_P_IP);
hdr4 = (struct iphdr *)skb_put(skb4, sizeof(*hdr4));
@@ -69,7 +69,7 @@ bool __init ratelimiter_selftest(void)
#if IS_ENABLED(CONFIG_IPV6)
skb6 = alloc_skb(sizeof(struct ipv6hdr), GFP_KERNEL);
- if (!skb6) {
+ if (unlikely(!skb6)) {
kfree_skb(skb4);
goto err_nofree;
}