mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>,
	"David S. Miller" <davem@davemloft.net>
Cc: Arnd Bergmann <arnd@arndb.de>,
	Greg KH <gregkh@linuxfoundation.org>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org, wireguard@lists.zx2c4.com,
	clang-built-linux@googlegroups.com
Subject: [PATCH] net: wireguard: avoid unused variable warning
Date: Tue,  5 May 2020 16:13:17 +0200	[thread overview]
Message-ID: <20200505141327.746184-1-arnd@arndb.de> (raw)

clang points out a harmless use of uninitialized variables that
get passed into a local function but are ignored there:

In file included from drivers/net/wireguard/ratelimiter.c:223:
drivers/net/wireguard/selftest/ratelimiter.c:173:34: error: variable 'skb6' is uninitialized when used here [-Werror,-Wuninitialized]
                ret = timings_test(skb4, hdr4, skb6, hdr6, &test_count);
                                               ^~~~
drivers/net/wireguard/selftest/ratelimiter.c:123:29: note: initialize the variable 'skb6' to silence this warning
        struct sk_buff *skb4, *skb6;
                                   ^
                                    = NULL
drivers/net/wireguard/selftest/ratelimiter.c:173:40: error: variable 'hdr6' is uninitialized when used here [-Werror,-Wuninitialized]
                ret = timings_test(skb4, hdr4, skb6, hdr6, &test_count);
                                                     ^~~~
drivers/net/wireguard/selftest/ratelimiter.c:125:22: note: initialize the variable 'hdr6' to silence this warning
        struct ipv6hdr *hdr6;
                            ^

Shut up the warning by ensuring the variables are always initialized,
and make up for the loss of readability by changing the "#if IS_ENABLED()"
checks to regular "if (IS_ENABLED())".

Fixes: e7096c131e51 ("net: WireGuard secure network tunnel")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/net/wireguard/selftest/ratelimiter.c | 32 +++++++++++---------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/drivers/net/wireguard/selftest/ratelimiter.c b/drivers/net/wireguard/selftest/ratelimiter.c
index bcd6462e4540..f408b936e224 100644
--- a/drivers/net/wireguard/selftest/ratelimiter.c
+++ b/drivers/net/wireguard/selftest/ratelimiter.c
@@ -153,19 +153,22 @@ bool __init wg_ratelimiter_selftest(void)
 	skb_reset_network_header(skb4);
 	++test;
 
-#if IS_ENABLED(CONFIG_IPV6)
-	skb6 = alloc_skb(sizeof(struct ipv6hdr), GFP_KERNEL);
-	if (unlikely(!skb6)) {
-		kfree_skb(skb4);
-		goto err_nofree;
+	if (IS_ENABLED(CONFIG_IPV6)) {
+		skb6 = alloc_skb(sizeof(struct ipv6hdr), GFP_KERNEL);
+		if (unlikely(!skb6)) {
+			kfree_skb(skb4);
+			goto err_nofree;
+		}
+		skb6->protocol = htons(ETH_P_IPV6);
+		hdr6 = (struct ipv6hdr *)skb_put(skb6, sizeof(*hdr6));
+		hdr6->saddr.in6_u.u6_addr32[0] = htonl(1212);
+		hdr6->saddr.in6_u.u6_addr32[1] = htonl(289188);
+		skb_reset_network_header(skb6);
+		++test;
+	} else {
+		skb6 = NULL;
+		hdr6 = NULL;
 	}
-	skb6->protocol = htons(ETH_P_IPV6);
-	hdr6 = (struct ipv6hdr *)skb_put(skb6, sizeof(*hdr6));
-	hdr6->saddr.in6_u.u6_addr32[0] = htonl(1212);
-	hdr6->saddr.in6_u.u6_addr32[1] = htonl(289188);
-	skb_reset_network_header(skb6);
-	++test;
-#endif
 
 	for (trials = TRIALS_BEFORE_GIVING_UP;;) {
 		int test_count = 0, ret;
@@ -206,9 +209,8 @@ bool __init wg_ratelimiter_selftest(void)
 
 err:
 	kfree_skb(skb4);
-#if IS_ENABLED(CONFIG_IPV6)
-	kfree_skb(skb6);
-#endif
+	if (IS_ENABLED(CONFIG_IPV6))
+		kfree_skb(skb6);
 err_nofree:
 	wg_ratelimiter_uninit();
 	wg_ratelimiter_uninit();
-- 
2.26.0


             reply	other threads:[~2020-05-05 14:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-05 14:13 Arnd Bergmann [this message]
2020-05-05 20:06 ` Jason A. Donenfeld
2020-05-05 20:51   ` Arnd Bergmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200505141327.746184-1-arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=Jason@zx2c4.com \
    --cc=clang-built-linux@googlegroups.com \
    --cc=davem@davemloft.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=wireguard@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®