All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rxrpc: avoid clang -Wuninitialized warning
@ 2019-03-22 14:18 Arnd Bergmann
  2019-03-22 15:22 ` Nathan Chancellor
  2019-03-24  1:49 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2019-03-22 14:18 UTC (permalink / raw)
  To: David Howells, David S. Miller
  Cc: clang-built-linux, Nick Desaulniers, Nathan Chancellor,
	Arnd Bergmann, YueHaibing, linux-afs, netdev, linux-kernel

clang produces a false-positive warning as it fails to notice
that "lost = true" implies that "ret" is initialized:

net/rxrpc/output.c:402:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
        if (lost)
            ^~~~
net/rxrpc/output.c:437:6: note: uninitialized use occurs here
        if (ret >= 0) {
            ^~~
net/rxrpc/output.c:402:2: note: remove the 'if' if its condition is always false
        if (lost)
        ^~~~~~~~~
net/rxrpc/output.c:339:9: note: initialize the variable 'ret' to silence this warning
        int ret, opt;
               ^
                = 0

Rearrange the code to make that more obvious and avoid the warning.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 net/rxrpc/output.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/net/rxrpc/output.c b/net/rxrpc/output.c
index 736aa9281100..004c762c2e8d 100644
--- a/net/rxrpc/output.c
+++ b/net/rxrpc/output.c
@@ -335,7 +335,6 @@ int rxrpc_send_data_packet(struct rxrpc_call *call, struct sk_buff *skb,
 	struct kvec iov[2];
 	rxrpc_serial_t serial;
 	size_t len;
-	bool lost = false;
 	int ret, opt;
 
 	_enter(",{%d}", skb->len);
@@ -393,14 +392,14 @@ int rxrpc_send_data_packet(struct rxrpc_call *call, struct sk_buff *skb,
 		static int lose;
 		if ((lose++ & 7) == 7) {
 			ret = 0;
-			lost = true;
+			trace_rxrpc_tx_data(call, sp->hdr.seq, serial,
+					    whdr.flags, retrans, true);
+			goto done;
 		}
 	}
 
-	trace_rxrpc_tx_data(call, sp->hdr.seq, serial, whdr.flags,
-			    retrans, lost);
-	if (lost)
-		goto done;
+	trace_rxrpc_tx_data(call, sp->hdr.seq, serial, whdr.flags, retrans,
+			    false);
 
 	/* send the packet with the don't fragment bit set if we currently
 	 * think it's small enough */
-- 
2.20.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] rxrpc: avoid clang -Wuninitialized warning
  2019-03-22 14:18 [PATCH] rxrpc: avoid clang -Wuninitialized warning Arnd Bergmann
@ 2019-03-22 15:22 ` Nathan Chancellor
  2019-03-24  1:49 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Nathan Chancellor @ 2019-03-22 15:22 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: David Howells, David S. Miller, clang-built-linux,
	Nick Desaulniers, YueHaibing, linux-afs, netdev, linux-kernel

On Fri, Mar 22, 2019 at 03:18:43PM +0100, Arnd Bergmann wrote:
> clang produces a false-positive warning as it fails to notice
> that "lost = true" implies that "ret" is initialized:
> 
> net/rxrpc/output.c:402:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
>         if (lost)
>             ^~~~
> net/rxrpc/output.c:437:6: note: uninitialized use occurs here
>         if (ret >= 0) {
>             ^~~
> net/rxrpc/output.c:402:2: note: remove the 'if' if its condition is always false
>         if (lost)
>         ^~~~~~~~~
> net/rxrpc/output.c:339:9: note: initialize the variable 'ret' to silence this warning
>         int ret, opt;
>                ^
>                 = 0
> 
> Rearrange the code to make that more obvious and avoid the warning.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>

> ---
>  net/rxrpc/output.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/net/rxrpc/output.c b/net/rxrpc/output.c
> index 736aa9281100..004c762c2e8d 100644
> --- a/net/rxrpc/output.c
> +++ b/net/rxrpc/output.c
> @@ -335,7 +335,6 @@ int rxrpc_send_data_packet(struct rxrpc_call *call, struct sk_buff *skb,
>  	struct kvec iov[2];
>  	rxrpc_serial_t serial;
>  	size_t len;
> -	bool lost = false;
>  	int ret, opt;
>  
>  	_enter(",{%d}", skb->len);
> @@ -393,14 +392,14 @@ int rxrpc_send_data_packet(struct rxrpc_call *call, struct sk_buff *skb,
>  		static int lose;
>  		if ((lose++ & 7) == 7) {
>  			ret = 0;
> -			lost = true;
> +			trace_rxrpc_tx_data(call, sp->hdr.seq, serial,
> +					    whdr.flags, retrans, true);
> +			goto done;
>  		}
>  	}
>  
> -	trace_rxrpc_tx_data(call, sp->hdr.seq, serial, whdr.flags,
> -			    retrans, lost);
> -	if (lost)
> -		goto done;
> +	trace_rxrpc_tx_data(call, sp->hdr.seq, serial, whdr.flags, retrans,
> +			    false);
>  
>  	/* send the packet with the don't fragment bit set if we currently
>  	 * think it's small enough */
> -- 
> 2.20.0
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rxrpc: avoid clang -Wuninitialized warning
  2019-03-22 14:18 [PATCH] rxrpc: avoid clang -Wuninitialized warning Arnd Bergmann
  2019-03-22 15:22 ` Nathan Chancellor
@ 2019-03-24  1:49 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2019-03-24  1:49 UTC (permalink / raw)
  To: arnd
  Cc: dhowells, clang-built-linux, ndesaulniers, natechancellor,
	yuehaibing, linux-afs, netdev, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>
Date: Fri, 22 Mar 2019 15:18:43 +0100

> clang produces a false-positive warning as it fails to notice
> that "lost = true" implies that "ret" is initialized:
 ...
> Rearrange the code to make that more obvious and avoid the warning.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Applied.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-03-24  1:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-22 14:18 [PATCH] rxrpc: avoid clang -Wuninitialized warning Arnd Bergmann
2019-03-22 15:22 ` Nathan Chancellor
2019-03-24  1:49 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.