blob: 285b92d5c665a14608ed8d661d7e082976c0df9e [file] [log] [blame]
Thomas Gleixner7f904d72019-06-04 10:11:38 +02001// SPDX-License-Identifier: GPL-2.0-only
Fabian Frederick791dfeb2014-08-08 14:23:29 -07002/// NULL check before some freeing functions is not needed.
3///
4/// Based on checkpatch warning
5/// "kfree(NULL) is safe this check is probably not required"
6/// and kfreeaddr.cocci by Julia Lawall.
7///
Thomas Gleixner7f904d72019-06-04 10:11:38 +02008// Copyright: (C) 2014 Fabian Frederick.
Fabian Frederick45715f32014-08-08 14:23:31 -07009// Comments: -
10// Options: --no-includes --include-headers
Fabian Frederick791dfeb2014-08-08 14:23:29 -070011
12virtual patch
13virtual org
14virtual report
15virtual context
16
17@r2 depends on patch@
18expression E;
19@@
Julia Lawallca047e72015-10-26 22:28:25 +010020- if (E != NULL)
Fabian Frederick791dfeb2014-08-08 14:23:29 -070021(
Julia Lawallca047e72015-10-26 22:28:25 +010022 kfree(E);
Fabian Frederick791dfeb2014-08-08 14:23:29 -070023|
Denis Efremov5e0c0742020-09-02 07:40:59 +030024 kvfree(E);
25|
Waiman Long453431a2020-08-06 23:18:13 -070026 kfree_sensitive(E);
Yann Droneaud6dd93792016-05-23 17:07:19 +020027|
Denis Efremov5e0c0742020-09-02 07:40:59 +030028 kvfree_sensitive(E, ...);
29|
30 vfree(E);
31|
Julia Lawallca047e72015-10-26 22:28:25 +010032 debugfs_remove(E);
Fabian Frederick791dfeb2014-08-08 14:23:29 -070033|
Julia Lawallca047e72015-10-26 22:28:25 +010034 debugfs_remove_recursive(E);
Fabian Frederick791dfeb2014-08-08 14:23:29 -070035|
Julia Lawallca047e72015-10-26 22:28:25 +010036 usb_free_urb(E);
Julia Lawall47437752015-10-26 22:28:26 +010037|
38 kmem_cache_destroy(E);
39|
40 mempool_destroy(E);
41|
42 dma_pool_destroy(E);
Fabian Frederick791dfeb2014-08-08 14:23:29 -070043)
44
45@r depends on context || report || org @
46expression E;
47position p;
48@@
49
Julia Lawallca047e72015-10-26 22:28:25 +010050* if (E != NULL)
Denis Efremov5e0c0742020-09-02 07:40:59 +030051* \(kfree@p\|kvfree@p\|kfree_sensitive@p\|kvfree_sensitive@p\|vfree@p\|
52* debugfs_remove@p\|debugfs_remove_recursive@p\|
Julia Lawall47437752015-10-26 22:28:26 +010053* usb_free_urb@p\|kmem_cache_destroy@p\|mempool_destroy@p\|
Denis Efremov5e0c0742020-09-02 07:40:59 +030054* dma_pool_destroy@p\)(E, ...);
Fabian Frederick791dfeb2014-08-08 14:23:29 -070055
56@script:python depends on org@
57p << r.p;
58@@
59
60cocci.print_main("NULL check before that freeing function is not needed", p)
61
62@script:python depends on report@
63p << r.p;
64@@
65
Himanshu Jha3e475992018-01-13 21:28:15 +053066msg = "WARNING: NULL check before some freeing functions is not needed."
Fabian Frederick791dfeb2014-08-08 14:23:29 -070067coccilib.report.print_report(p[0], msg)