From: Joe Perches <joe@perches.com>
To: Julia Lawall <julia.lawall@lip6.fr>
Cc: Dan Carpenter <error27@gmail.com>,
LKML <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
netdev <netdev@vger.kernel.org>
Subject: Re: Possible code defects: macros and precedence
Date: Tue, 20 Sep 2016 11:03:44 -0700 [thread overview]
Message-ID: <1474394624.1954.45.camel@perches.com> (raw)
In-Reply-To: <1474391253.1954.39.camel@perches.com>
On Tue, 2016-09-20 at 10:07 -0700, Joe Perches wrote:
> On Tue, 2016-09-20 at 15:14 +0200, Julia Lawall wrote:
> > The semantic patch below finds a binary operator in a macro and a binary
> > operator in the use of the macro, and checks if the priority of the
> > operator in the macro is higher (lower number) than the priority of the
> > operator in the use. If this is the case, it adds parentheses in the use,
> > which is not what one wants, but serves to show where the problem is
> Thanks, this works on the trivial example I suggested
> without an #include
>
> I've tried it on trivial files with --recursive-includes
> and it seems to work there too.
I tried it on drivers/net with --recursive-includes and got
just 1 hit on an old and probably relatively untested driver.
No hardware, can't test. It may be correct now. Who knows...
---
diff --urN a/drivers/net/ethernet/smsc/smc911x.h b/drivers/net/ethernet/smsc/smc911x.h
--- a/drivers/net/ethernet/smsc/smc911x.h
+++ b/drivers/net/ethernet/smsc/smc911x.h
@@ -700,8 +700,8 @@ static const struct chip_id chip_ids[] =
* capabilities. Please use those and not the in/out primitives.
*/
/* FIFO read/write macros */
-#define SMC_PUSH_DATA(lp, p, l) SMC_outsl( lp, TX_DATA_FIFO, p, (l) >> 2 )
-#define SMC_PULL_DATA(lp, p, l) SMC_insl ( lp, RX_DATA_FIFO, p, (l) >> 2 )
+#define SMC_PUSH_DATA(lp, p, l) SMC_outsl( lp, TX_DATA_FIFO, p, ((l) >> 2) )
+#define SMC_PULL_DATA(lp, p, l) SMC_insl ( lp, RX_DATA_FIFO, p, ((l) >> 2) )
#define SMC_SET_TX_FIFO(lp, x) SMC_outl( x, lp, TX_DATA_FIFO )
#define SMC_GET_RX_FIFO(lp) SMC_inl( lp, RX_DATA_FIFO )
next prev parent reply other threads:[~2016-09-20 18:03 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-03 18:35 Possible code defects: macros and precedence Joe Perches
2016-09-03 20:18 ` Dan Carpenter
2016-09-03 22:20 ` [PATCH] checkpatch: Add a --strict test for macro argument reuse " Joe Perches
2016-09-04 14:42 ` Joe Perches
2016-09-04 10:10 ` Possible code defects: macros " Julia Lawall
2016-09-04 15:06 ` Joe Perches
[not found] ` <alpine.DEB.2.10.1609172221110.3124@hadrien>
2016-09-17 21:27 ` Joe Perches
2016-09-18 5:09 ` Julia Lawall
2016-09-18 9:31 ` Joe Perches
2016-09-20 13:14 ` Julia Lawall
2016-09-20 17:07 ` Joe Perches
2016-09-20 18:03 ` Joe Perches [this message]
2016-09-20 23:47 ` Joe Perches
2016-09-21 5:04 ` Julia Lawall
2016-09-17 21:57 ` Joe Perches
2016-09-18 4:57 ` Julia Lawall
2016-09-18 9:27 ` Joe Perches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1474394624.1954.45.camel@perches.com \
--to=joe@perches.com \
--cc=akpm@linux-foundation.org \
--cc=error27@gmail.com \
--cc=julia.lawall@lip6.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox