* [PATCH 05/14] isdn: isdnloop: suppress a gcc-7 warning [not found] <20170714092540.1217397-1-arnd@arndb.de> @ 2017-07-14 9:25 ` Arnd Bergmann 2017-07-14 10:08 ` Joe Perches 0 siblings, 1 reply; 4+ messages in thread From: Arnd Bergmann @ 2017-07-14 9:25 UTC (permalink / raw) To: linux-kernel, Karsten Keil, David S. Miller Cc: Arnd Bergmann, Greg Kroah-Hartman, dri-devel, linux-ide, netdev, Tejun Heo, akpm, Linus Torvalds, Guenter Roeck, linux-media We test whether a bit is set in a mask here, which is correct but gcc warns about it as it thinks it might be confusing: drivers/isdn/isdnloop/isdnloop.c:412:37: error: ?: using integer constants in boolean context, the expression will always evaluate to 'true' [-Werror=int-in-bool-context] This replaces the negation of an integer with an equivalent comparison to zero, which gets rid of the warning. Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- drivers/isdn/isdnloop/isdnloop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/isdn/isdnloop/isdnloop.c b/drivers/isdn/isdnloop/isdnloop.c index 6ffd13466b8c..5792928b944d 100644 --- a/drivers/isdn/isdnloop/isdnloop.c +++ b/drivers/isdn/isdnloop/isdnloop.c @@ -409,7 +409,7 @@ isdnloop_sendbuf(int channel, struct sk_buff *skb, isdnloop_card *card) return -EINVAL; } if (len) { - if (!(card->flags & (channel) ? ISDNLOOP_FLAGS_B2ACTIVE : ISDNLOOP_FLAGS_B1ACTIVE)) + if ((card->flags & (channel) ? ISDNLOOP_FLAGS_B2ACTIVE : ISDNLOOP_FLAGS_B1ACTIVE) == 0) return 0; if (card->sndcount[channel] > ISDNLOOP_MAX_SQUEUE) return 0; -- 2.9.0 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 05/14] isdn: isdnloop: suppress a gcc-7 warning 2017-07-14 9:25 ` [PATCH 05/14] isdn: isdnloop: suppress a gcc-7 warning Arnd Bergmann @ 2017-07-14 10:08 ` Joe Perches 2017-07-14 10:37 ` Arnd Bergmann 0 siblings, 1 reply; 4+ messages in thread From: Joe Perches @ 2017-07-14 10:08 UTC (permalink / raw) To: Arnd Bergmann, linux-kernel, Karsten Keil, David S. Miller Cc: Greg Kroah-Hartman, Linus Torvalds, Tejun Heo, Guenter Roeck, linux-ide, linux-media, akpm, dri-devel, netdev On Fri, 2017-07-14 at 11:25 +0200, Arnd Bergmann wrote: > We test whether a bit is set in a mask here, which is correct > but gcc warns about it as it thinks it might be confusing: > > drivers/isdn/isdnloop/isdnloop.c:412:37: error: ?: using integer constants in boolean context, the expression will always evaluate to 'true' [-Werror=int-in-bool-context] > > This replaces the negation of an integer with an equivalent > comparison to zero, which gets rid of the warning. [] > diff --git a/drivers/isdn/isdnloop/isdnloop.c b/drivers/isdn/isdnloop/isdnloop.c [] > @@ -409,7 +409,7 @@ isdnloop_sendbuf(int channel, struct sk_buff *skb, isdnloop_card *card) > return -EINVAL; > } > if (len) { > - if (!(card->flags & (channel) ? ISDNLOOP_FLAGS_B2ACTIVE : ISDNLOOP_FLAGS_B1ACTIVE)) > + if ((card->flags & (channel) ? ISDNLOOP_FLAGS_B2ACTIVE : ISDNLOOP_FLAGS_B1ACTIVE) == 0) > return 0; > if (card->sndcount[channel] > ISDNLOOP_MAX_SQUEUE) > return 0; The if as written can not be zero. drivers/isdn/isdnloop/isdnloop.h:#define ISDNLOOP_FLAGS_B1ACTIVE 1 /* B-Channel-1 is open */ drivers/isdn/isdnloop/isdnloop.h:#define ISDNLOOP_FLAGS_B2ACTIVE 2 /* B-Channel-2 is open */ Perhaps this is a logic defect and should be: if (!(card->flags & ((channel) ? ISDNLOOP_FLAGS_B2ACTIVE : ISDNLOOP_FLAGS_B1ACTIVE))) ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 05/14] isdn: isdnloop: suppress a gcc-7 warning 2017-07-14 10:08 ` Joe Perches @ 2017-07-14 10:37 ` Arnd Bergmann 2017-07-15 4:20 ` Kevin Easton 0 siblings, 1 reply; 4+ messages in thread From: Arnd Bergmann @ 2017-07-14 10:37 UTC (permalink / raw) To: Joe Perches Cc: Linux Kernel Mailing List, Karsten Keil, David S. Miller, Greg Kroah-Hartman, Linus Torvalds, Tejun Heo, Guenter Roeck, IDE-ML, Linux Media Mailing List, Andrew Morton, dri-devel, Networking On Fri, Jul 14, 2017 at 12:08 PM, Joe Perches <joe@perches.com> wrote: > On Fri, 2017-07-14 at 11:25 +0200, Arnd Bergmann wrote: >> We test whether a bit is set in a mask here, which is correct >> but gcc warns about it as it thinks it might be confusing: >> >> drivers/isdn/isdnloop/isdnloop.c:412:37: error: ?: using integer constants in boolean context, the expression will always evaluate to 'true' [-Werror=int-in-bool-context] >> >> This replaces the negation of an integer with an equivalent >> comparison to zero, which gets rid of the warning. > [] >> diff --git a/drivers/isdn/isdnloop/isdnloop.c b/drivers/isdn/isdnloop/isdnloop.c > [] >> @@ -409,7 +409,7 @@ isdnloop_sendbuf(int channel, struct sk_buff *skb, isdnloop_card *card) >> return -EINVAL; >> } >> if (len) { >> - if (!(card->flags & (channel) ? ISDNLOOP_FLAGS_B2ACTIVE : ISDNLOOP_FLAGS_B1ACTIVE)) >> + if ((card->flags & (channel) ? ISDNLOOP_FLAGS_B2ACTIVE : ISDNLOOP_FLAGS_B1ACTIVE) == 0) >> return 0; >> if (card->sndcount[channel] > ISDNLOOP_MAX_SQUEUE) >> return 0; > > The if as written can not be zero. > > drivers/isdn/isdnloop/isdnloop.h:#define ISDNLOOP_FLAGS_B1ACTIVE 1 /* B-Channel-1 is open */ > drivers/isdn/isdnloop/isdnloop.h:#define ISDNLOOP_FLAGS_B2ACTIVE 2 /* B-Channel-2 is open */ > > Perhaps this is a logic defect and should be: > > if (!(card->flags & ((channel) ? ISDNLOOP_FLAGS_B2ACTIVE : ISDNLOOP_FLAGS_B1ACTIVE))) Yes, good catch. I had thought about it for a bit whether that would be the answer, but come to the wrong conclusion on my own. Note that the version you suggested will still have the warning, so I think it needs to be if (card->flags & ((channel) ? ISDNLOOP_FLAGS_B2ACTIVE : ISDNLOOP_FLAGS_B1ACTIVE) == 0) or something like that, probably having a temporary flag variable would be best: int flag = channel ? ISDNLOOP_FLAGS_B2ACTIVE : ISDNLOOP_FLAGS_B1ACTIVE; if ((card->flags & flag) == 0) return 0; Arnd ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 05/14] isdn: isdnloop: suppress a gcc-7 warning 2017-07-14 10:37 ` Arnd Bergmann @ 2017-07-15 4:20 ` Kevin Easton 0 siblings, 0 replies; 4+ messages in thread From: Kevin Easton @ 2017-07-15 4:20 UTC (permalink / raw) To: Arnd Bergmann Cc: Joe Perches, Linux Kernel Mailing List, Karsten Keil, David S. Miller, Greg Kroah-Hartman, Linus Torvalds, Tejun Heo, Guenter Roeck, IDE-ML, Linux Media Mailing List, Andrew Morton, dri-devel, Networking On Fri, Jul 14, 2017 at 12:37:05PM +0200, Arnd Bergmann wrote: > On Fri, Jul 14, 2017 at 12:08 PM, Joe Perches <joe@perches.com> wrote: > > On Fri, 2017-07-14 at 11:25 +0200, Arnd Bergmann wrote: > >> We test whether a bit is set in a mask here, which is correct > >> but gcc warns about it as it thinks it might be confusing: > >> > >> drivers/isdn/isdnloop/isdnloop.c:412:37: error: ?: using integer constants in boolean context, the expression will always evaluate to 'true' [-Werror=int-in-bool-context] ... > > Perhaps this is a logic defect and should be: > > > > if (!(card->flags & ((channel) ? ISDNLOOP_FLAGS_B2ACTIVE : ISDNLOOP_FLAGS_B1ACTIVE))) > > Yes, good catch. I had thought about it for a bit whether that would be > the answer, but come to the wrong conclusion on my own. > > Note that the version you suggested will still have the warning, so I think > it needs to be It shouldn't - the warning is for using an integer *constant* in boolean context, but the result of & isn't a constant and should be fine. !(flags & mask) is a very common idiom. - Kevin ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-07-15 4:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20170714092540.1217397-1-arnd@arndb.de>
2017-07-14 9:25 ` [PATCH 05/14] isdn: isdnloop: suppress a gcc-7 warning Arnd Bergmann
2017-07-14 10:08 ` Joe Perches
2017-07-14 10:37 ` Arnd Bergmann
2017-07-15 4:20 ` Kevin Easton
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).