2020-04-19 09:56:02 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2017-11-10 18:15:02 +00: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.
|
|
|
|
///
|
2020-04-19 09:56:02 +00:00
|
|
|
// Copyright: (C) 2014 Fabian Frederick.
|
2017-11-10 18:15:02 +00:00
|
|
|
// Comments: -
|
|
|
|
// Options: --no-includes --include-headers
|
|
|
|
|
|
|
|
virtual patch
|
|
|
|
virtual org
|
|
|
|
virtual report
|
|
|
|
virtual context
|
|
|
|
|
|
|
|
@r2 depends on patch@
|
|
|
|
expression E;
|
|
|
|
@@
|
|
|
|
- if (E != NULL)
|
|
|
|
(
|
2020-04-19 09:56:02 +00:00
|
|
|
free(E);
|
2017-11-10 18:15:02 +00:00
|
|
|
|
|
2020-04-19 09:56:02 +00:00
|
|
|
kfree(E);
|
2017-11-10 18:15:02 +00:00
|
|
|
|
|
2020-04-19 09:56:02 +00:00
|
|
|
vfree(E);
|
2017-11-10 18:15:02 +00:00
|
|
|
|
|
2020-04-19 09:56:02 +00:00
|
|
|
vfree_recursive(E);
|
2017-11-10 18:15:02 +00:00
|
|
|
|
|
2020-04-19 09:56:02 +00:00
|
|
|
kmem_cache_free(E);
|
2017-11-10 18:15:02 +00:00
|
|
|
|
|
|
|
|
kmem_cache_destroy(E);
|
|
|
|
|
|
2020-04-19 09:56:02 +00:00
|
|
|
gzfree(E);
|
2017-11-10 18:15:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
@r depends on context || report || org @
|
|
|
|
expression E;
|
|
|
|
position p;
|
|
|
|
@@
|
|
|
|
|
|
|
|
* if (E != NULL)
|
2020-04-19 09:56:02 +00:00
|
|
|
* \(free@p\|kfree@p\|vfree@p\|debugfs_remove_recursive@p\|
|
|
|
|
* kmem_cache_free@p\|kmem_cache_destroy@p\|gzfree@p\)(E);
|
2017-11-10 18:15:02 +00: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;
|
|
|
|
@@
|
|
|
|
|
2020-04-19 09:56:02 +00:00
|
|
|
msg = "WARNING: NULL check before some freeing functions is not needed."
|
2017-11-10 18:15:02 +00:00
|
|
|
coccilib.report.print_report(p[0], msg)
|