* [PATCH 1/2] NFSv4.1: work around -Wmaybe-uninitialized warning
@ 2016-08-31 12:39 Arnd Bergmann
2016-08-31 13:17 ` Trond Myklebust
0 siblings, 1 reply; 5+ messages in thread
From: Arnd Bergmann @ 2016-08-31 12:39 UTC (permalink / raw)
To: Trond Myklebust, Anna Schumaker
Cc: netdev, Arnd Bergmann, linux-nfs, linux-kernel
A bugfix introduced a harmless gcc warning in nfs4_slot_seqid_in_use:
fs/nfs/nfs4session.c:203:54: error: 'cur_seq' may be used uninitialized in this function [-Werror=maybe-uninitialized]
gcc is not smart enough to conclude that the IS_ERR/PTR_ERR pair
results in a nonzero return value here. Using PTR_ERR_OR_ZERO()
instead makes this clear to the compiler.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: e09c978aae5b ("NFSv4.1: Fix Oopsable condition in server callback races")
---
fs/nfs/nfs4session.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
The patch that caused this just came in for v4.8-rc5. As the warning
is now disabled by default and this is harmless, this can probably
get queued for v4.9 instead.
I mentioned earlier that I got the new warning for net-next, but
failed to notice that it had come from mainline instead.
diff --git a/fs/nfs/nfs4session.c b/fs/nfs/nfs4session.c
index b62973045a3e..150c5a1879bf 100644
--- a/fs/nfs/nfs4session.c
+++ b/fs/nfs/nfs4session.c
@@ -178,12 +178,14 @@ static int nfs4_slot_get_seqid(struct nfs4_slot_table *tbl, u32 slotid,
__must_hold(&tbl->slot_tbl_lock)
{
struct nfs4_slot *slot;
+ int ret;
slot = nfs4_lookup_slot(tbl, slotid);
- if (IS_ERR(slot))
- return PTR_ERR(slot);
- *seq_nr = slot->seq_nr;
- return 0;
+ ret = PTR_ERR_OR_ZERO(slot);
+ if (!ret)
+ *seq_nr = slot->seq_nr;
+
+ return ret;
}
/*
--
2.9.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH 1/2] NFSv4.1: work around -Wmaybe-uninitialized warning 2016-08-31 12:39 [PATCH 1/2] NFSv4.1: work around -Wmaybe-uninitialized warning Arnd Bergmann @ 2016-08-31 13:17 ` Trond Myklebust 2016-08-31 13:37 ` Arnd Bergmann 0 siblings, 1 reply; 5+ messages in thread From: Trond Myklebust @ 2016-08-31 13:17 UTC (permalink / raw) To: Arnd Bergmann Cc: Schumaker Anna, List Linux Network Devel Mailing, List Linux NFS Mailing, List Linux Kernel Mailing > On Aug 31, 2016, at 08:39, Arnd Bergmann <arnd@arndb.de> wrote: >=20 > A bugfix introduced a harmless gcc warning in nfs4_slot_seqid_in_use: >=20 > fs/nfs/nfs4session.c:203:54: error: 'cur_seq' may be used uninitialized i= n this function [-Werror=3Dmaybe-uninitialized] >=20 > gcc is not smart enough to conclude that the IS_ERR/PTR_ERR pair > results in a nonzero return value here. Using PTR_ERR_OR_ZERO() > instead makes this clear to the compiler. >=20 > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > Fixes: e09c978aae5b ("NFSv4.1: Fix Oopsable condition in server callback = races") > --- > fs/nfs/nfs4session.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) >=20 > The patch that caused this just came in for v4.8-rc5. As the warning > is now disabled by default and this is harmless, this can probably > get queued for v4.9 instead. >=20 > I mentioned earlier that I got the new warning for net-next, but > failed to notice that it had come from mainline instead. >=20 > diff --git a/fs/nfs/nfs4session.c b/fs/nfs/nfs4session.c > index b62973045a3e..150c5a1879bf 100644 > --- a/fs/nfs/nfs4session.c > +++ b/fs/nfs/nfs4session.c > @@ -178,12 +178,14 @@ static int nfs4_slot_get_seqid(struct nfs4_slot_tab= le *tbl, u32 slotid, > =09__must_hold(&tbl->slot_tbl_lock) > { > =09struct nfs4_slot *slot; > +=09int ret; >=20 > =09slot =3D nfs4_lookup_slot(tbl, slotid); > -=09if (IS_ERR(slot)) > -=09=09return PTR_ERR(slot); > -=09*seq_nr =3D slot->seq_nr; > -=09return 0; > +=09ret =3D PTR_ERR_OR_ZERO(slot); > +=09if (!ret) > +=09=09*seq_nr =3D slot->seq_nr; > + > +=09return ret; > } >=20 What version of gcc are you using? I=92m unable to reproduce with gcc 6.1.1= .. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] NFSv4.1: work around -Wmaybe-uninitialized warning 2016-08-31 13:17 ` Trond Myklebust @ 2016-08-31 13:37 ` Arnd Bergmann 2016-08-31 15:02 ` Trond Myklebust 0 siblings, 1 reply; 5+ messages in thread From: Arnd Bergmann @ 2016-08-31 13:37 UTC (permalink / raw) To: Trond Myklebust Cc: Schumaker Anna, List Linux Network Devel Mailing, List Linux NFS Mailing, List Linux Kernel Mailing On Wednesday, August 31, 2016 1:17:48 PM CEST Trond Myklebust wrote: > What version of gcc are you using? I’m unable to reproduce with gcc 6.1.1.. This is also on 6.1.1 for ARM. Note that 6e8d666e9253 ("Disable "maybe-uninitialized" warning globally") turned off those warnings, so unless you explicitly pass -Wmaybe-uninitialized (e.g. by building with "make W=1"), you won't get it. The reason I'm still sending the patches for this warning is that we do get a number of valid ones (this was the only false positive out of the seven such warnings since last week). Arnd ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] NFSv4.1: work around -Wmaybe-uninitialized warning 2016-08-31 13:37 ` Arnd Bergmann @ 2016-08-31 15:02 ` Trond Myklebust 2016-08-31 15:52 ` Arnd Bergmann 0 siblings, 1 reply; 5+ messages in thread From: Trond Myklebust @ 2016-08-31 15:02 UTC (permalink / raw) To: Arnd Bergmann Cc: Schumaker Anna, List Linux Network Devel Mailing, List Linux NFS Mailing, List Linux Kernel Mailing DQo+IE9uIEF1ZyAzMSwgMjAxNiwgYXQgMDk6MzcsIEFybmQgQmVyZ21hbm4gPGFybmRAYXJuZGIu ZGU+IHdyb3RlOg0KPiANCj4gT24gV2VkbmVzZGF5LCBBdWd1c3QgMzEsIDIwMTYgMToxNzo0OCBQ TSBDRVNUIFRyb25kIE15a2xlYnVzdCB3cm90ZToNCj4+IFdoYXQgdmVyc2lvbiBvZiBnY2MgYXJl IHlvdSB1c2luZz8gSeKAm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HJvbmQ= ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] NFSv4.1: work around -Wmaybe-uninitialized warning 2016-08-31 15:02 ` Trond Myklebust @ 2016-08-31 15:52 ` Arnd Bergmann 0 siblings, 0 replies; 5+ messages in thread From: Arnd Bergmann @ 2016-08-31 15:52 UTC (permalink / raw) To: Trond Myklebust Cc: Schumaker Anna, List Linux Network Devel Mailing, List Linux NFS Mailing, List Linux Kernel Mailing On Wednesday, August 31, 2016 3:02:42 PM CEST Trond Myklebust wrote: > > On Aug 31, 2016, at 09:37, Arnd Bergmann <arnd@arndb.de> wrote: > > > > On Wednesday, August 31, 2016 1:17:48 PM CEST Trond Myklebust wrote: > >> What version of gcc are you using? I’m unable to reproduce with gcc 6.1.1.. > > > > This is also on 6.1.1 for ARM. Note that 6e8d666e9253 ("Disable > > "maybe-uninitialized" warning globally") turned off those warnings, so > > unless you explicitly pass -Wmaybe-uninitialized (e.g. by building with > > "make W=1"), you won't get it. > > > > I’m not getting that error on gcc 6.1.1 for x86_64 with either “make W=1” or “make W=2”. > “make W=3” does gives rise to one warning in nfs4_slot_get_seqid: Ok, I had not realized that the patch that Linus did disabled the warning for all levels, I'll try to come up a patch to bring it back at W=1 level. On my system, I had simply reverted the patch that turned off the warning, but I have now verified that I get it with "make EXTRA_CFLAGS=-Wmaybe-uninitialized" on an x86 defconfig with gcc-5 and gcc-6. > /home/trondmy/devel/kernel/linux/fs/nfs/nfs4session.c: In function ‘nfs4_slot_get_seqid’: > /home/trondmy/devel/kernel/linux/fs/nfs/nfs4session.c:184:10: warning: conversion to ‘int’ from ‘long int’ may alter its value [-Wconversion] > return PTR_ERR(slot); > ^~~~~~~~~~~~~ > > (which is another false positive) but that’s all... sure, W=3 is useless. > > The reason I'm still sending the patches for this warning is that > > we do get a number of valid ones (this was the only false positive > > out of the seven such warnings since last week). > > There is a Zen-like quality to IS_ERR() when it casts a const pointer to an unsigned long, back to a non-const pointer, and then back to an unsigned long before comparing it to another unsigned long cast constant negative integer. However, I’m not sure the C99 standard would agree that a positive test result implies we can assume that a simple cast of the same pointer to a signed long will result in a negative, non-zero valued errno. > > I suspect that if we really want to fix these false negatives, we should probably address that issue. I've looked into this before, as we've had a couple of these cases (I think less than 10 in the whole kernel, but they keep coming up every few releases), and I couldn't find a way to make IS_ERR more transparent. Using IS_ERR_OR_ZERO() seems like a good enough solution, and will probably result in slightly better code (I have not checked this specific case though), as we can also skip the second runtime check. Arnd ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-08-31 15:52 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-08-31 12:39 [PATCH 1/2] NFSv4.1: work around -Wmaybe-uninitialized warning Arnd Bergmann 2016-08-31 13:17 ` Trond Myklebust 2016-08-31 13:37 ` Arnd Bergmann 2016-08-31 15:02 ` Trond Myklebust 2016-08-31 15:52 ` Arnd Bergmann
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox