diff mbox series

inet: Avoid unitialized variable warning in inet_unhash()

Message ID 1517480783-5692-1-git-send-email-geert@linux-m68k.org
State Accepted, archived
Delegated to: David Miller
Headers show
Series inet: Avoid unitialized variable warning in inet_unhash() | expand

Commit Message

Geert Uytterhoeven Feb. 1, 2018, 10:26 a.m. UTC
With gcc-4.1.2:

    net/ipv4/inet_hashtables.c: In function ‘inet_unhash’:
    net/ipv4/inet_hashtables.c:628: warning: ‘ilb’ may be used uninitialized in this function

While this is a false positive, it can easily be avoided by using the
pointer itself as the canary variable.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 net/ipv4/inet_hashtables.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Arnd Bergmann Feb. 1, 2018, 11:48 a.m. UTC | #1
On Thu, Feb 1, 2018 at 11:26 AM, Geert Uytterhoeven
<geert@linux-m68k.org> wrote:
> With gcc-4.1.2:
>
>     net/ipv4/inet_hashtables.c: In function ‘inet_unhash’:
>     net/ipv4/inet_hashtables.c:628: warning: ‘ilb’ may be used uninitialized in this function
>
> While this is a false positive, it can easily be avoided by using the
> pointer itself as the canary variable.
>
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>

Looks like a reasonable workaround if we care about it. gcc-4.3 and higher
don't seem to produce this warning, so I wouldn't normally care though.

Acked-by: Arnd Bergmann <arnd@arndb.de>
David Miller Feb. 1, 2018, 2:49 p.m. UTC | #2
From: Geert Uytterhoeven <geert@linux-m68k.org>

Date: Thu,  1 Feb 2018 11:26:23 +0100

> With gcc-4.1.2:

> 

>     net/ipv4/inet_hashtables.c: In function ‘inet_unhash’:

>     net/ipv4/inet_hashtables.c:628: warning: ‘ilb’ may be used uninitialized in this function

> 

> While this is a false positive, it can easily be avoided by using the

> pointer itself as the canary variable.

> 

> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>


This frankly also makes the logic simpler and doesn't increase register
pressure, I like it.

Applied, thanks.
diff mbox series

Patch

diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index 37b7da0b975dc297..31ff46daae974645 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -625,9 +625,8 @@  EXPORT_SYMBOL_GPL(inet_hash);
 void inet_unhash(struct sock *sk)
 {
 	struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo;
-	struct inet_listen_hashbucket *ilb;
+	struct inet_listen_hashbucket *ilb = NULL;
 	spinlock_t *lock;
-	bool listener = false;
 
 	if (sk_unhashed(sk))
 		return;
@@ -635,7 +634,6 @@  void inet_unhash(struct sock *sk)
 	if (sk->sk_state == TCP_LISTEN) {
 		ilb = &hashinfo->listening_hash[inet_sk_listen_hashfn(sk)];
 		lock = &ilb->lock;
-		listener = true;
 	} else {
 		lock = inet_ehash_lockp(hashinfo, sk->sk_hash);
 	}
@@ -645,7 +643,7 @@  void inet_unhash(struct sock *sk)
 
 	if (rcu_access_pointer(sk->sk_reuseport_cb))
 		reuseport_detach_sock(sk);
-	if (listener) {
+	if (ilb) {
 		inet_unhash2(hashinfo, sk);
 		 __sk_del_node_init(sk);
 		 ilb->count--;