From: Joe Perches <joe@perches.com>
To: Ding Tianhong <dthxman@gmail.com>
Cc: Ding Tianhong <dingtianhong@huawei.com>,
"David S. Miller" <davem@davemloft.net>,
Netdev <netdev@vger.kernel.org>
Subject: Re: [PATCH net-next v2 0/6] slight optimization of addr compare for some modules
Date: Mon, 16 Dec 2013 07:16:46 -0800 [thread overview]
Message-ID: <1387207006.18217.28.camel@joe-AO722> (raw)
In-Reply-To: <52AF13F4.5040409@gmail.com>
On Mon, 2013-12-16 at 22:53 +0800, Ding Tianhong wrote:
> 于 2013/12/16 22:45, Joe Perches 写道:
> > Are you intending to do more of these?
> >
> > $ git grep -E "\bmemcmp\s*\([^,]*,[^,]*,\s*(ETH_ALEN|6)\s*\)" * | wc -l
> > 299
> >
> > Perhaps the majority of these should use ether_addr_equal
> > or ether_addr_equal_unaligned.
>
> yes, it is a juge work to review the whole places and I think it should be
> finished by several times, maybe start from this patchset.
coccinelle (aka: spatch) can help find and change these
$ cat ether_addr_equal_unaligned.cocci
@@
expression e1;
expression e2;
@@
- !memcmp(e1, e2, 6)
+ ether_addr_equal_unaligned(e1, e2)
@@
expression e1;
expression e2;
@@
- memcmp(e1, e2, 6) == 0
+ ether_addr_equal_unaligned(e1, e2)
@@
expression e1;
expression e2;
@@
- memcmp(e1, e2, 6)
+ !ether_addr_equal_unaligned(e1, e2)
@@
expression e1;
expression e2;
@@
- memcmp(e1, e2, 6) != 0
+ !ether_addr_equal_unaligned(e1, e2)
$ spatch -sp-file ether_addr_equal.cocci drivers/media/dvb-core/dvb_net.c
init_defs_builtins: /usr/local/share/coccinelle/standard.h
HANDLING: drivers/media/dvb-core/dvb_net.c
diff =
--- drivers/media/dvb-core/dvb_net.c
+++ /tmp/cocci-output-18744-96d16c-dvb_net.c
@@ -837,7 +837,8 @@ static void dvb_net_sec(struct net_devic
}
if (pkt[5] & 0x02) {
/* handle LLC/SNAP, see rfc-1042 */
- if (pkt_len < 24 || memcmp(&pkt[12], "\xaa\xaa\x03\0\0\0", 6)) {
+ if (pkt_len < 24 || !ether_addr_equal_unaligned(&pkt[12],
+ "\xaa\xaa\x03\0\0\0")) {
stats->rx_dropped++;
return;
}
I presume many of these should be ether_addr_equal
and not ether_addr_equal_unaligned, but I can't
think of a way to automate that easily.
next prev parent reply other threads:[~2013-12-16 15:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-16 8:24 [PATCH net-next v2 0/6] slight optimization of addr compare for some modules Ding Tianhong
2013-12-16 14:45 ` Joe Perches
2013-12-16 14:53 ` Ding Tianhong
2013-12-16 15:16 ` Joe Perches [this message]
2013-12-16 17:25 ` Joe Perches
2013-12-17 1:58 ` Ding Tianhong
2013-12-18 8:47 ` Ding Tianhong
2013-12-18 9:17 ` Joe Perches
2013-12-18 9:35 ` Ding Tianhong
2013-12-18 10:06 ` Ding Tianhong
2013-12-18 16:51 ` Joe Perches
2013-12-19 1:24 ` Ding Tianhong
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=1387207006.18217.28.camel@joe-AO722 \
--to=joe@perches.com \
--cc=davem@davemloft.net \
--cc=dingtianhong@huawei.com \
--cc=dthxman@gmail.com \
--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