2014-08-09 04:23:29 +07: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 04:23:31 +07:00
// Copyright: (C) 2014 Fabian Frederick. GPLv2.
// Comments: -
// Options: --no-includes --include-headers
2014-08-09 04:23:29 +07:00
virtual patch
virtual org
virtual report
virtual context
@r2 depends on patch@
expression E;
@@
2015-10-27 04:28:25 +07:00
- if (E != NULL)
2014-08-09 04:23:29 +07:00
(
2015-10-27 04:28:25 +07:00
kfree(E);
2016-05-23 22:07:19 +07:00
|
kzfree(E);
2014-08-09 04:23:29 +07:00
|
2015-10-27 04:28:25 +07:00
debugfs_remove(E);
2014-08-09 04:23:29 +07:00
|
2015-10-27 04:28:25 +07:00
debugfs_remove_recursive(E);
2014-08-09 04:23:29 +07:00
|
2015-10-27 04:28:25 +07:00
usb_free_urb(E);
2015-10-27 04:28:26 +07:00
|
kmem_cache_destroy(E);
|
mempool_destroy(E);
|
dma_pool_destroy(E);
2014-08-09 04:23:29 +07:00
)
@r depends on context || report || org @
expression E;
position p;
@@
2015-10-27 04:28:25 +07:00
* if (E != NULL)
2016-05-23 22:07:19 +07:00
* \(kfree@p\|kzfree@p\|debugfs_remove@p\|debugfs_remove_recursive@p\|
2015-10-27 04:28:26 +07:00
* usb_free_urb@p\|kmem_cache_destroy@p\|mempool_destroy@p\|
* dma_pool_destroy@p\)(E);
2014-08-09 04:23:29 +07: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;
@@
msg = "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."
coccilib.report.print_report(p[0], msg)