From: Joe Perches <joe@perches.com>
To: Julia Lawall <julia.lawall@lip6.fr>
Cc: cocci <cocci@systeme.lip6.fr>,
LKML <linux-kernel@vger.kernel.org>,
Dan Carpenter <error27@gmail.com>,
kernel-janitors <kernel-janitors@vger.kernel.org>
Subject: coccinelle: generalized removal of unnecessary pointer casts?
Date: Mon, 14 Mar 2016 11:54:30 -0700 [thread overview]
Message-ID: <1457981670.11972.114.camel@perches.com> (raw)
I wrote a little cocci script to remove unnecessary
casts for memset and memcpy (below) and tested it on
linux kernel's drivers/staging/ directory.
For instance, when dst and src are already pointers:
- memcpy((u8 *)dst, (u8 *)src, r8712_get_wlan_bssid_ex_sz(src));
+ memcpy(dst, src, r8712_get_wlan_bssid_ex_sz(src));
It works ok, (it doesn't remove unnecessary parentheses
around the pointers) but it makes me wonder if there's a
generalized spatch mechanism to remove casts when an
arbitrary function takes a void * in any argument
position and a call to that function uses a cast of a
pointer to any pointer type for that argument.
$ cat remove_mem_casts.cocci
@@
type t;
t *p;
type v;
expression e1;
expression e2;
@@
- memset((v*)p, e1, e2)
+ memset(p, e1, e2)
@@
type t;
t *p;
type v;
expression e1;
expression e2;
@@
- memcpy((v*)p, e1, e2)
+ memcpy(p, e1, e2)
@@
type t;
t *p;
type v;
expression e1;
expression e2;
@@
- memcpy(e1, (v*)p, e2)
+ memcpy(e1, p, e2)
@@
type t1;
type t2;
t1 *p1;
t2 *p2;
type v1;
type v2;
expression e1;
@@
- memcpy((v1*)p1, (v2*)p2, e1)
+ memcpy(p1, p2, e1)
next reply other threads:[~2016-03-14 18:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-14 18:54 Joe Perches [this message]
2016-03-14 20:43 ` coccinelle: generalized removal of unnecessary pointer casts? Julia Lawall
2016-03-14 22:23 ` Joe Perches
2016-03-15 5:54 ` Julia Lawall
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=1457981670.11972.114.camel@perches.com \
--to=joe@perches.com \
--cc=cocci@systeme.lip6.fr \
--cc=error27@gmail.com \
--cc=julia.lawall@lip6.fr \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@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