* [PATCH] tipc: avoid a clang -Wuninitialized warning
@ 2019-03-22 14:18 Arnd Bergmann
2019-03-22 16:12 ` 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: Jon Maloy, Ying Xue, David S. Miller
Cc: clang-built-linux, Nick Desaulniers, Nathan Chancellor,
Arnd Bergmann, Tuong Lien, LUU Duc Canh, Tung Nguyen,
GhantaKrishnamurthy MohanKrishna, netdev, tipc-discussion,
linux-kernel
clang notices that we pass 'maddr' into the tipc_bearer_xmit() function
without having initialized it first:
net/tipc/node.c:831:6: error: variable 'maddr' is used uninitialized whenever 'if' condition is false
[-Werror,-Wsometimes-uninitialized]
if (!tipc_link_is_establishing(l)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
net/tipc/node.c:847:46: note: uninitialized use occurs here
tipc_bearer_xmit(n->net, bearer_id, &xmitq, maddr);
^~~~~
net/tipc/node.c:831:2: note: remove the 'if' if its condition is always true
if (!tipc_link_is_establishing(l)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
net/tipc/node.c:821:31: note: initialize the variable 'maddr' to silence this warning
struct tipc_media_addr *maddr;
^
= NULL
This is harmless because it won't use 'maddr' if the
queue is empty, but it's better to make that explicit
and not even call the function in that case.
As clang is able to inline the check, it then notices that
the code is safe.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
net/tipc/node.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/tipc/node.c b/net/tipc/node.c
index 2dc4919ab23c..ca4cafd00a38 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -844,7 +844,8 @@ static void tipc_node_link_down(struct tipc_node *n, int bearer_id, bool delete)
tipc_node_write_unlock(n);
if (delete)
tipc_mon_remove_peer(n->net, n->addr, old_bearer_id);
- tipc_bearer_xmit(n->net, bearer_id, &xmitq, maddr);
+ if (!skb_queue_empty(&xmitq))
+ tipc_bearer_xmit(n->net, bearer_id, &xmitq, maddr);
tipc_sk_rcv(n->net, &le->inputq);
}
--
2.20.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] tipc: avoid a clang -Wuninitialized warning
2019-03-22 14:18 [PATCH] tipc: avoid a clang -Wuninitialized warning Arnd Bergmann
@ 2019-03-22 16:12 ` Nathan Chancellor
2019-03-24 1:49 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Nathan Chancellor @ 2019-03-22 16:12 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Jon Maloy, Ying Xue, David S. Miller, clang-built-linux,
Nick Desaulniers, Tuong Lien, LUU Duc Canh, Tung Nguyen,
GhantaKrishnamurthy MohanKrishna, netdev, tipc-discussion,
linux-kernel
On Fri, Mar 22, 2019 at 03:18:13PM +0100, Arnd Bergmann wrote:
> clang notices that we pass 'maddr' into the tipc_bearer_xmit() function
> without having initialized it first:
>
> net/tipc/node.c:831:6: error: variable 'maddr' is used uninitialized whenever 'if' condition is false
> [-Werror,-Wsometimes-uninitialized]
> if (!tipc_link_is_establishing(l)) {
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> net/tipc/node.c:847:46: note: uninitialized use occurs here
> tipc_bearer_xmit(n->net, bearer_id, &xmitq, maddr);
> ^~~~~
> net/tipc/node.c:831:2: note: remove the 'if' if its condition is always true
> if (!tipc_link_is_establishing(l)) {
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> net/tipc/node.c:821:31: note: initialize the variable 'maddr' to silence this warning
> struct tipc_media_addr *maddr;
> ^
> = NULL
>
> This is harmless because it won't use 'maddr' if the
> queue is empty, but it's better to make that explicit
> and not even call the function in that case.
>
> As clang is able to inline the check, it then notices that
> the code is safe.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Thanks for looking into this and fixing it!
Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
> ---
> net/tipc/node.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/net/tipc/node.c b/net/tipc/node.c
> index 2dc4919ab23c..ca4cafd00a38 100644
> --- a/net/tipc/node.c
> +++ b/net/tipc/node.c
> @@ -844,7 +844,8 @@ static void tipc_node_link_down(struct tipc_node *n, int bearer_id, bool delete)
> tipc_node_write_unlock(n);
> if (delete)
> tipc_mon_remove_peer(n->net, n->addr, old_bearer_id);
> - tipc_bearer_xmit(n->net, bearer_id, &xmitq, maddr);
> + if (!skb_queue_empty(&xmitq))
> + tipc_bearer_xmit(n->net, bearer_id, &xmitq, maddr);
> tipc_sk_rcv(n->net, &le->inputq);
> }
>
> --
> 2.20.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tipc: avoid a clang -Wuninitialized warning
2019-03-22 14:18 [PATCH] tipc: avoid a clang -Wuninitialized warning Arnd Bergmann
2019-03-22 16:12 ` 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: jon.maloy, ying.xue, clang-built-linux, ndesaulniers,
natechancellor, tuong.t.lien, canh.d.luu, tung.q.nguyen,
mohan.krishna.ghanta.krishnamurthy, netdev, tipc-discussion,
linux-kernel
From: Arnd Bergmann <arnd@arndb.de>
Date: Fri, 22 Mar 2019 15:18:13 +0100
> clang notices that we pass 'maddr' into the tipc_bearer_xmit() function
> without having initialized it first:
...
> This is harmless because it won't use 'maddr' if the
> queue is empty, but it's better to make that explicit
> and not even call the function in that case.
>
> As clang is able to inline the check, it then notices that
> the code is safe.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
It looks like Jon's patch took care of this.
^ 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] tipc: avoid a clang -Wuninitialized warning Arnd Bergmann
2019-03-22 16:12 ` 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.