Skip to content

Commit

Permalink
scripts/coccinelle/api/simple_open.cocci: semantic patch for simple_o…
Browse files Browse the repository at this point in the history
…pen()

Find instances of an open-coded simple_open() and replace them with
calls to simple_open().

Signed-off-by: Julia Lawall <[email protected]>
Reported-by: Stephen Boyd <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
JuliaLawall authored and torvalds committed Apr 5, 2012
1 parent 20955e8 commit 9b3ae64
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions scripts/coccinelle/api/simple_open.cocci
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/// This removes an open coded simple_open() function
/// and replaces file operations references to the function
/// with simple_open() instead.
///
// Confidence: High
// Comments:
// Options: -no_includes -include_headers

virtual patch
virtual report

@ open depends on patch @
identifier open_f != simple_open;
identifier i, f;
@@
-int open_f(struct inode *i, struct file *f)
-{
(
-if (i->i_private)
-f->private_data = i->i_private;
|
-f->private_data = i->i_private;
)
-return 0;
-}

@ has_open depends on open @
identifier fops;
identifier open.open_f;
@@
struct file_operations fops = {
...,
-.open = open_f,
+.open = simple_open,
...
};

@ openr depends on report @
identifier open_f != simple_open;
identifier i, f;
position p;
@@
int open_f@p(struct inode *i, struct file *f)
{
(
if (i->i_private)
f->private_data = i->i_private;
|
f->private_data = i->i_private;
)
return 0;
}

@ has_openr depends on openr @
identifier fops;
identifier openr.open_f;
position p;
@@
struct file_operations fops = {
...,
.open = open_f@p,
...
};

@script:python@
pf << openr.p;
ps << has_openr.p;
@@
coccilib.report.print_report(pf[0],"WARNING opportunity for simple_open, see also structure on line %s"%(ps[0].line))

0 comments on commit 9b3ae64

Please sign in to comment.