In 6e8d666e9253 ("Disable "maybe-uninitialized" warning globally"),
Linus wrote:
Looking at the warnings produced, every single one I looked at was a
false positive, and the warnings are frequent enough (and big enough)
that they can easily hide real problems that you don't notice in
the noise generated by -Wmaybe-uninitialized.
Today, I tried reverting the patch on linux-next and built an ARM
allmodconfig kernel on ARM along with some randconfig kernels,
and got a handful of warnings, all of which appear to be reasonable
and point to actual mistakes in the code. The difference to what
Linus saw must be that previously the useful warnings were more
likely to get fixed before making it into the kernel, while now
we have to find them the hard way.
These five patches address all new warnings. In some cases this
may not be the correct fix, so please review carefully before applying,
or suggest a better fix. No need to keep them as a series, I
just group them here for the sake of discussion. Please pick up
whatever looks right to you.
Obviously, this kind of warnings always produces some false positives
(see https://gcc.gnu.org/wiki/Better_Uninitialized_Warnings), but I still
hope to get a better balance with enabling them sometimes where
people want them, as the current approach of always enabling them
for "make W=1" but never by default seems suboptimal: We had previously
identified a number of options (CONFIG_CC_OPTIMIZE_FOR_SIZE,
CONFIG_PROFILE_ALL_BRANCHES, CONFIG_UBSAN_ALIGNMENT, and
CONFIG_GCOV_PROFILE_ALL) that cause tons of false positives,
but without those options (and avoiding gcc-4.8 or lower),
we typically get mostly reports for actual bugs in my experience.
I can continue running the tests and send patches, but it feels
like a waste of time when they should have been found by the
original developers. Any other suggestions?
Arnd
Arnd Bergmann (5):
gpio: pca954x: fix undefined error code from remove
video: ARM CLCD: fix endpoint lookup logic
rxrpc: fix last_call processing
net_sched: fix use of uninitialized ethertype variable in cls_flower
net/xgene: fix error handling during reset
drivers/gpio/gpio-pca953x.c | 2 ++
drivers/net/ethernet/apm/xgene/xgene_enet_xgmac.c | 12 +++++++++---
drivers/video/fbdev/amba-clcd.c | 9 +++------
net/rxrpc/input.c | 8 ++++----
net/sched/cls_flower.c | 21 +++++++++++----------
5 files changed, 29 insertions(+), 23 deletions(-)
Cc: Alexandre Courbot <redacted>
Cc: David Howells <dhowells@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Fushen Chen <redacted>
Cc: Hadar Hen Zion <redacted>
Cc: Iyappan Subramanian <redacted>
Cc: Jiri Pirko <redacted>
Cc: Keyur Chudgar <redacted>
Cc: Linus Walleij <redacted>
Cc: Phil Reid <redacted>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Tomi Valkeinen <redacted>
Cc: linux-fbdev@vger.kernel.org
Cc: linux-gpio@vger.kernel.org
Cc: netdev@vger.kernel.org
--
2.9.0
The newly added reset logic uses helper functions for the MMIO that
may fail. However, when the read operation fails, we end up writing
back uninitialized data to the register, as gcc warns:
drivers/net/ethernet/apm/xgene/xgene_enet_xgmac.c: In function 'xgene_enet_link_state':
drivers/net/ethernet/apm/xgene/xgene_enet_xgmac.c:213:2: error: 'data' may be used uninitialized in this function [-Werror=maybe-uninitialized]
drivers/net/ethernet/apm/xgene/xgene_enet_xgmac.c:209:6: note: 'data' was declared here
u32 data;
We already print a warning to the console log if that happens,
the best alternative that I can see is skip the rest of the reset
sequence if the register value cannot be read: Most likely the
write would fail as well, and if it succeeded, worse things could
happen.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: 3eb7cb9dc946 ("drivers: net: xgene: XFI PCS reset when link is down")
Cc: Fushen Chen <redacted>
---
Cc: Iyappan Subramanian <redacted>
Cc: Keyur Chudgar <redacted>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org
drivers/net/ethernet/apm/xgene/xgene_enet_xgmac.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
The addition of VLAN support caused a possible use of uninitialized
data if we encounter a zero TCA_FLOWER_KEY_ETH_TYPE key, as pointed
out by "gcc -Wmaybe-uninitialized":
net/sched/cls_flower.c: In function 'fl_change':
net/sched/cls_flower.c:366:22: error: 'ethertype' may be used uninitialized in this function [-Werror=maybe-uninitialized]
This changes the code to only set the ethertype field if it
was nonzero, as before the patch.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: 9399ae9a6cb2 ("net_sched: flower: Add vlan support")
Cc: Hadar Hen Zion <redacted>
Cc: Jiri Pirko <redacted>
---
Cc: David S. Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org
net/sched/cls_flower.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
A change to the retransmission handling in rxrpc caused a use-before-init
bug in rxrpc_data_ready(), as indicated by "gcc -Wmaybe-uninitialized":
net/rxrpc/input.c: In function 'rxrpc_data_ready':
net/rxrpc/input.c:735:34: error: 'call' may be used uninitialized in this function [-Werror=maybe-uninitialized]
This moves the initialization of the local variable before the first
user, which presumably is what was intended here.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: 18bfeba50dfd ("rxrpc: Perform terminal call ACK/ABORT retransmission from conn processor")
---
Cc: David Howells <dhowells@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org
net/rxrpc/input.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
@@ -728,6 +728,10 @@ void rxrpc_data_ready(struct sock *sk)if(sp->hdr.callNumber<chan->last_call)gotodiscard_unlock;+call=rcu_dereference(chan->call);+if(!call||atomic_read(&call->usage)==0)+gotocant_route_call;+if(sp->hdr.callNumber==chan->last_call){/* For the previous service call, if completed*successfully,wediscardallfurtherpackets.
From: David Howells <dhowells@redhat.com> Date: 2016-08-27 07:01:47
Arnd Bergmann [off-list ref] wrote:
quoted hunk
A change to the retransmission handling in rxrpc caused a use-before-init
bug in rxrpc_data_ready(), as indicated by "gcc -Wmaybe-uninitialized":
net/rxrpc/input.c: In function 'rxrpc_data_ready':
net/rxrpc/input.c:735:34: error: 'call' may be used uninitialized in this function [-Werror=maybe-uninitialized]
This moves the initialization of the local variable before the first
user, which presumably is what was intended here.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: 18bfeba50dfd ("rxrpc: Perform terminal call ACK/ABORT retransmission from conn processor")
---
Cc: David Howells <dhowells@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org
net/rxrpc/input.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
@@ -728,6 +728,10 @@ void rxrpc_data_ready(struct sock *sk)if(sp->hdr.callNumber<chan->last_call)gotodiscard_unlock;+call=rcu_dereference(chan->call);+if(!call||atomic_read(&call->usage)==0)+gotocant_route_call;+if(sp->hdr.callNumber==chan->last_call){/* For the previous service call, if completed*successfully,wediscardallfurtherpackets.
The addition of VLAN support caused a possible use of uninitialized
data if we encounter a zero TCA_FLOWER_KEY_ETH_TYPE key, as pointed
out by "gcc -Wmaybe-uninitialized":
net/sched/cls_flower.c: In function 'fl_change':
net/sched/cls_flower.c:366:22: error: 'ethertype' may be used uninitialized in this function [-Werror=maybe-uninitialized]
This changes the code to only set the ethertype field if it
was nonzero, as before the patch.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: 9399ae9a6cb2 ("net_sched: flower: Add vlan support")
The newly added reset logic uses helper functions for the MMIO that
may fail. However, when the read operation fails, we end up writing
back uninitialized data to the register, as gcc warns:
drivers/net/ethernet/apm/xgene/xgene_enet_xgmac.c: In function 'xgene_enet_link_state':
drivers/net/ethernet/apm/xgene/xgene_enet_xgmac.c:213:2: error: 'data' may be used uninitialized in this function [-Werror=maybe-uninitialized]
drivers/net/ethernet/apm/xgene/xgene_enet_xgmac.c:209:6: note: 'data' was declared here
u32 data;
We already print a warning to the console log if that happens,
the best alternative that I can see is skip the rest of the reset
sequence if the register value cannot be read: Most likely the
write would fail as well, and if it succeeded, worse things could
happen.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: 3eb7cb9dc946 ("drivers: net: xgene: XFI PCS reset when link is down")
On Sunday, August 28, 2016 9:42:17 AM CEST David Howells wrote:
This is fixed by:
commit 2266ffdef5737fdfa96005204fc5606dbd559956
subject: rxrpc: Fix conn-based retransmit
which is in net-next.
I've merged net-next into the last linux-next release now for
testing (no linux-next this week) and can confirm that your
fix is correct. However, I got a new (valid) warning after
your f5c17aaeb2ae ("rxrpc: Calls should only have one terminal
state"), and another (false-positive) one for another patch
in net-next.
I'll follow up with the fixes, both of which are rather
straightforward.
Arnd