2014-08-09 05:23:29 +08:00
|
|
|
/// NULL check before some freeing functions is not needed.
|
|
|
|
///
|
|
|
|
/// Based on checkpatch warning
|
|
|
|
/// "kfree(NULL) is safe this check is probably not required"
|
|
|
|
/// and kfreeaddr.cocci by Julia Lawall.
|
|
|
|
///
|
2014-08-09 05:23:31 +08:00
|
|
|
// Copyright: (C) 2014 Fabian Frederick. GPLv2.
|
|
|
|
// Comments: -
|
|
|
|
// Options: --no-includes --include-headers
|
2014-08-09 05:23:29 +08:00
|
|
|
|
|
|
|
virtual patch
|
|
|
|
virtual org
|
|
|
|
virtual report
|
|
|
|
virtual context
|
|
|
|
|
|
|
|
@r2 depends on patch@
|
|
|
|
expression E;
|
|
|
|
@@
|
2015-10-27 05:28:25 +08:00
|
|
|
- if (E != NULL)
|
2014-08-09 05:23:29 +08:00
|
|
|
(
|
2015-10-27 05:28:25 +08:00
|
|
|
kfree(E);
|
2016-05-23 23:07:19 +08:00
|
|
|
|
|
|
|
|
kzfree(E);
|
2014-08-09 05:23:29 +08:00
|
|
|
|
|
2015-10-27 05:28:25 +08:00
|
|
|
debugfs_remove(E);
|
2014-08-09 05:23:29 +08:00
|
|
|
|
|
2015-10-27 05:28:25 +08:00
|
|
|
debugfs_remove_recursive(E);
|
2014-08-09 05:23:29 +08:00
|
|
|
|
|
2015-10-27 05:28:25 +08:00
|
|
|
usb_free_urb(E);
|
2015-10-27 05:28:26 +08:00
|
|
|
|
|
|
|
|
kmem_cache_destroy(E);
|
|
|
|
|
|
|
|
|
mempool_destroy(E);
|
|
|
|
|
|
|
|
|
dma_pool_destroy(E);
|
2014-08-09 05:23:29 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
@r depends on context || report || org @
|
|
|
|
expression E;
|
|
|
|
position p;
|
|
|
|
@@
|
|
|
|
|
2015-10-27 05:28:25 +08:00
|
|
|
* if (E != NULL)
|
2016-05-23 23:07:19 +08:00
|
|
|
* \(kfree@p\|kzfree@p\|debugfs_remove@p\|debugfs_remove_recursive@p\|
|
2015-10-27 05:28:26 +08:00
|
|
|
* usb_free_urb@p\|kmem_cache_destroy@p\|mempool_destroy@p\|
|
|
|
|
* dma_pool_destroy@p\)(E);
|
2014-08-09 05:23:29 +08:00
|
|
|
|
|
|
|
@script:python depends on org@
|
|
|
|
p << r.p;
|
|
|
|
@@
|
|
|
|
|
|
|
|
cocci.print_main("NULL check before that freeing function is not needed", p)
|
|
|
|
|
|
|
|
@script:python depends on report@
|
|
|
|
p << r.p;
|
|
|
|
@@
|
|
|
|
|
2018-01-13 23:58:15 +08:00
|
|
|
msg = "WARNING: NULL check before some freeing functions is not needed."
|
2014-08-09 05:23:29 +08:00
|
|
|
coccilib.report.print_report(p[0], msg)
|