[Cocci] Remove unnecessary null pointer checks?

Julia Lawall julia.lawall at lip6.fr
Tue Feb 25 18:42:30 CET 2014



On Tue, 25 Feb 2014, SF Markus Elfring wrote:

> > 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?
>
> @Delete_unnecessary_checks@
> expression x;
> identifier release =~ "^(?x)
> (?:
>    (?:kz?|slob_)free
> |
>    (?:
>       abc
>    |  xyz
>    )
> )$";
> @@
> -if (x)
>     release(...,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(_)

I don't think it is a good approach to do anything related to 5142
different functions at once.  It would be better to pick a small set of
functions, and work on them carefully.

julia


More information about the Cocci mailing list