aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/selftest
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 /src/selftest
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>
Diffstat (limited to 'src/selftest')
-rw-r--r--src/selftest/allowedips.h10
-rw-r--r--src/selftest/ratelimiter.h4
2 files changed, 7 insertions, 7 deletions
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;
}