1/// NULL check before some freeing functions is not needed.
2///
3/// Based on checkpatch warning
4/// "kfree(NULL) is safe this check is probably not required"
5/// and kfreeaddr.cocci by Julia Lawall.
6///
7// Copyright: (C) 2014 Fabian Frederick.  GPLv2.
8// Comments: -
9// Options: --no-includes --include-headers
10
11virtual patch
12virtual org
13virtual report
14virtual context
15
16@r2 depends on patch@
17expression E;
18@@
19- if (E)
20(
21-	kfree(E);
22+ kfree(E);
23|
24-	debugfs_remove(E);
25+ debugfs_remove(E);
26|
27-	debugfs_remove_recursive(E);
28+ debugfs_remove_recursive(E);
29|
30-	usb_free_urb(E);
31+ usb_free_urb(E);
32)
33
34@r depends on context || report || org @
35expression E;
36position p;
37@@
38
39* if (E)
40*	\(kfree@p\|debugfs_remove@p\|debugfs_remove_recursive@p\|usb_free_urb\)(E);
41
42@script:python depends on org@
43p << r.p;
44@@
45
46cocci.print_main("NULL check before that freeing function is not needed", p)
47
48@script:python depends on report@
49p << r.p;
50@@
51
52msg = "WARNING: NULL check before freeing functions like kfree, debugfs_remove, debugfs_remove_recursive or usb_free_urb is not needed. Maybe consider reorganizing relevant code to avoid passing NULL values."
53coccilib.report.print_report(p[0], msg)
54