Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1721805 > unrolled thread

cocci: remove unnecessary casts of void * while avoiding casts with __user or __force ?

Started byJoe Perches <joe@perches.com>
First post2017-08-28 18:50 +0200
Last post2017-08-29 07:30 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  cocci: remove unnecessary casts of void * while avoiding casts with  __user or __force ? Joe Perches <joe@perches.com> - 2017-08-28 18:50 +0200
    Re: [Cocci] cocci: remove unnecessary casts of void * while avoiding  casts with __user or __force ? Julia Lawall <julia.lawall@lip6.fr> - 2017-08-29 07:30 +0200

#1721805 — cocci: remove unnecessary casts of void * while avoiding casts with __user or __force ?

FromJoe Perches <joe@perches.com>
Date2017-08-28 18:50 +0200
Subjectcocci: remove unnecessary casts of void * while avoiding casts with __user or __force ?
Message-ID<ujvoD-7Xb-35@gated-at.bofh.it>
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,
	...)

$

[toc] | [next] | [standalone]


#1722148 — Re: [Cocci] cocci: remove unnecessary casts of void * while avoiding casts with __user or __force ?

FromJulia Lawall <julia.lawall@lip6.fr>
Date2017-08-29 07:30 +0200
SubjectRe: [Cocci] cocci: remove unnecessary casts of void * while avoiding casts with __user or __force ?
Message-ID<ujHg5-6VW-1@gated-at.bofh.it>
In reply to#1721805

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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web