blob: d4a072d5b505fd5a8655cc4c389a34367745bbf5 [file] [log] [blame]
Fabian Frederick791dfeb2014-08-08 14:23:29 -07001/// 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///
Fabian Frederick45715f32014-08-08 14:23:31 -07007// Copyright: (C) 2014 Fabian Frederick. GPLv2.
8// Comments: -
9// Options: --no-includes --include-headers
Fabian Frederick791dfeb2014-08-08 14:23:29 -070010
11virtual patch
12virtual org
13virtual report
14virtual context
15
16@r2 depends on patch@
17expression E;
18@@
Julia Lawallca047e72015-10-26 22:28:25 +010019- if (E != NULL)
Fabian Frederick791dfeb2014-08-08 14:23:29 -070020(
Julia Lawallca047e72015-10-26 22:28:25 +010021 kfree(E);
Fabian Frederick791dfeb2014-08-08 14:23:29 -070022|
Julia Lawallca047e72015-10-26 22:28:25 +010023 debugfs_remove(E);
Fabian Frederick791dfeb2014-08-08 14:23:29 -070024|
Julia Lawallca047e72015-10-26 22:28:25 +010025 debugfs_remove_recursive(E);
Fabian Frederick791dfeb2014-08-08 14:23:29 -070026|
Julia Lawallca047e72015-10-26 22:28:25 +010027 usb_free_urb(E);
Fabian Frederick791dfeb2014-08-08 14:23:29 -070028)
29
30@r depends on context || report || org @
31expression E;
32position p;
33@@
34
Julia Lawallca047e72015-10-26 22:28:25 +010035* if (E != NULL)
36* \(kfree@p\|debugfs_remove@p\|debugfs_remove_recursive@p\|usb_free_urb@p\)(E);
Fabian Frederick791dfeb2014-08-08 14:23:29 -070037
38@script:python depends on org@
39p << r.p;
40@@
41
42cocci.print_main("NULL check before that freeing function is not needed", p)
43
44@script:python depends on report@
45p << r.p;
46@@
47
48msg = "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."
49coccilib.report.print_report(p[0], msg)