public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* cocci: remove unnecessary casts of void * while avoiding casts with __user or __force ?
@ 2017-08-28 16:49 Joe Perches
  2017-08-29  5:17 ` [Cocci] " Julia Lawall
  0 siblings, 1 reply; 2+ messages in thread
From: Joe Perches @ 2017-08-28 16:49 UTC (permalink / raw)
  To: cocci; +Cc: LKML

A simple cocci script that removes unnecessary casts of
a void * will also remove casts with __force or __user

e.g.:

-       xemaclite_aligned_write(address_ptr, (u32 __force *) addr, ETH_ALEN);
+       xemaclite_aligned_write(address_ptr, addr, ETH_ALEN);

Is there a simple mechanism to avoid converting those?

$ cat void.cocci
@@
type T;
void *v;
expression e;
@@

-	e = (T *)v;
+	e = v;

@@
identifier f;
type T;
void *v;
@@

	f(...,
-	(T *)v,
+	v,
	...)

$

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Cocci] cocci: remove unnecessary casts of void * while avoiding casts with __user or __force ?
  2017-08-28 16:49 cocci: remove unnecessary casts of void * while avoiding casts with __user or __force ? Joe Perches
@ 2017-08-29  5:17 ` Julia Lawall
  0 siblings, 0 replies; 2+ messages in thread
From: Julia Lawall @ 2017-08-29  5:17 UTC (permalink / raw)
  To: Joe Perches; +Cc: cocci, LKML



On Mon, 28 Aug 2017, Joe Perches wrote:

> A simple cocci script that removes unnecessary casts of
> a void * will also remove casts with __force or __user

Unfortunately, attributes are currently not supported inside casts.  This
can be done in a hackish way (possible false negatives) as follows:

---

@initialize:ocaml@
@@

let close (p1,p2) =
  let r = (List.hd p1).line_end in
  let l = (List.hd p2).line in
  let rc = (List.hd p1).col_end in
  let lc = (List.hd p2).col in
  r = l && lc = rc+1

@r@
position p1,p2;
expression f,e;
type T;
@@

f(..., // generalize this rule as needed
 (T@p1 *@p2)
 e,...)

@@
position r.p2 : script:ocaml(r.p1) { close(p1,p2) };
position r.p1;
expression e;
type T;
@@

- (T@p1 *@p2)
  e

---

Basically, it assumes that if the type and the * are more than one space
apart then there is something important there, and the cast is not
removed.

julia

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-08-29  5:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-28 16:49 cocci: remove unnecessary casts of void * while avoiding casts with __user or __force ? Joe Perches
2017-08-29  5:17 ` [Cocci] " Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox