2019-06-04 10:11:38 +02:00
// SPDX-License-Identifier: GPL-2.0-only
2014-08-08 14: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.
///
2019-06-04 10:11:38 +02:00
// Copyright: (C) 2014 Fabian Frederick.
2014-08-08 14:23:31 -07:00
// Comments: -
// Options: --no-includes --include-headers
2014-08-08 14:23:29 -07:00
virtual patch
virtual org
virtual report
virtual context
@r2 depends on patch@
expression E;
@@
2015-10-26 22:28:25 +01:00
- if (E != NULL)
2014-08-08 14:23:29 -07:00
(
2015-10-26 22:28:25 +01:00
kfree(E);
2016-05-23 17:07:19 +02:00
|
kzfree(E);
2014-08-08 14:23:29 -07:00
|
2015-10-26 22:28:25 +01:00
debugfs_remove(E);
2014-08-08 14:23:29 -07:00
|
2015-10-26 22:28:25 +01:00
debugfs_remove_recursive(E);
2014-08-08 14:23:29 -07:00
|
2015-10-26 22:28:25 +01:00
usb_free_urb(E);
2015-10-26 22:28:26 +01:00
|
kmem_cache_destroy(E);
|
mempool_destroy(E);
|
dma_pool_destroy(E);
2014-08-08 14:23:29 -07:00
)
@r depends on context || report || org @
expression E;
position p;
@@
2015-10-26 22:28:25 +01:00
* if (E != NULL)
2016-05-23 17:07:19 +02:00
* \(kfree@p\|kzfree@p\|debugfs_remove@p\|debugfs_remove_recursive@p\|
2015-10-26 22:28:26 +01:00
* usb_free_urb@p\|kmem_cache_destroy@p\|mempool_destroy@p\|
* dma_pool_destroy@p\)(E);
2014-08-08 14: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;
@@
2018-01-13 21:28:15 +05:30
msg = "WARNING: NULL check before some freeing functions is not needed."
2014-08-08 14:23:29 -07:00
coccilib.report.print_report(p[0], msg)