[Cocci] Remove unnecessary null pointer checks?

SF Markus Elfring elfring at users.sourceforge.net
Tue Feb 25 18:28:36 CET 2014

> I'm not sure to understand your goal.

I get an interesting result for example if I try the following source code
search pattern out. Do you find it useful?

expression x;
identifier release =~ "^(?x)
   |  xyz
-if (x)

elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch --sp-file
delete_unnecessary_checks1.cocci /usr/src/linux-stable/fs/btrfs/inode.c
init_defs_builtins: /usr/local/share/coccinelle/standard.h
HANDLING: /usr/src/linux-stable/fs/btrfs/inode.c
diff =
--- /usr/src/linux-stable/fs/btrfs/inode.c
+++ /tmp/cocci-output-3740-5d95d8-inode.c
@@ -5137,8 +5137,7 @@ static int btrfs_dentry_delete(const str

 static void btrfs_dentry_release(struct dentry *dentry)
-       if (dentry->d_fsdata)
-               kfree(dentry->d_fsdata);
+       kfree(dentry->d_fsdata);

> If you remove the NULL test, you could drastically change the behavior
> of the program.

But it seems that I stumble on a software debug challenge after I replaced the
dummy alternation in the regular expression above by the real list of 5142
function names which were found by the other discussed pattern.

elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch --sp-file
delete_unnecessary_checks2.cocci /usr/src/linux-stable/fs/btrfs/inode.c
init_defs_builtins: /usr/local/share/coccinelle/standard.h
Fatal error: exception Pcre.Error(_)


More information about the Cocci mailing list