Heinrich Schuchardt | c11f0d8 | 2020-04-19 11:56:02 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Heinrich Schuchardt | 06feb5d | 2017-11-10 19:15:02 +0100 | [diff] [blame] | 2 | /// 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 | /// |
Heinrich Schuchardt | c11f0d8 | 2020-04-19 11:56:02 +0200 | [diff] [blame] | 8 | // Copyright: (C) 2014 Fabian Frederick. |
Heinrich Schuchardt | 06feb5d | 2017-11-10 19:15:02 +0100 | [diff] [blame] | 9 | // Comments: - |
| 10 | // Options: --no-includes --include-headers |
| 11 | |
| 12 | virtual patch |
| 13 | virtual org |
| 14 | virtual report |
| 15 | virtual context |
| 16 | |
| 17 | @r2 depends on patch@ |
| 18 | expression E; |
| 19 | @@ |
| 20 | - if (E != NULL) |
| 21 | ( |
Heinrich Schuchardt | c11f0d8 | 2020-04-19 11:56:02 +0200 | [diff] [blame] | 22 | free(E); |
| 23 | | |
Heinrich Schuchardt | 06feb5d | 2017-11-10 19:15:02 +0100 | [diff] [blame] | 24 | kfree(E); |
| 25 | | |
Heinrich Schuchardt | c11f0d8 | 2020-04-19 11:56:02 +0200 | [diff] [blame] | 26 | vfree(E); |
Heinrich Schuchardt | 06feb5d | 2017-11-10 19:15:02 +0100 | [diff] [blame] | 27 | | |
Heinrich Schuchardt | c11f0d8 | 2020-04-19 11:56:02 +0200 | [diff] [blame] | 28 | vfree_recursive(E); |
Heinrich Schuchardt | 06feb5d | 2017-11-10 19:15:02 +0100 | [diff] [blame] | 29 | | |
Heinrich Schuchardt | c11f0d8 | 2020-04-19 11:56:02 +0200 | [diff] [blame] | 30 | kmem_cache_free(E); |
Heinrich Schuchardt | 06feb5d | 2017-11-10 19:15:02 +0100 | [diff] [blame] | 31 | | |
| 32 | kmem_cache_destroy(E); |
| 33 | | |
Heinrich Schuchardt | c11f0d8 | 2020-04-19 11:56:02 +0200 | [diff] [blame] | 34 | gzfree(E); |
Heinrich Schuchardt | 06feb5d | 2017-11-10 19:15:02 +0100 | [diff] [blame] | 35 | ) |
| 36 | |
| 37 | @r depends on context || report || org @ |
| 38 | expression E; |
| 39 | position p; |
| 40 | @@ |
| 41 | |
| 42 | * if (E != NULL) |
Heinrich Schuchardt | c11f0d8 | 2020-04-19 11:56:02 +0200 | [diff] [blame] | 43 | * \(free@p\|kfree@p\|vfree@p\|debugfs_remove_recursive@p\| |
| 44 | * kmem_cache_free@p\|kmem_cache_destroy@p\|gzfree@p\)(E); |
Heinrich Schuchardt | 06feb5d | 2017-11-10 19:15:02 +0100 | [diff] [blame] | 45 | |
| 46 | @script:python depends on org@ |
| 47 | p << r.p; |
| 48 | @@ |
| 49 | |
| 50 | cocci.print_main("NULL check before that freeing function is not needed", p) |
| 51 | |
| 52 | @script:python depends on report@ |
| 53 | p << r.p; |
| 54 | @@ |
| 55 | |
Heinrich Schuchardt | c11f0d8 | 2020-04-19 11:56:02 +0200 | [diff] [blame] | 56 | msg = "WARNING: NULL check before some freeing functions is not needed." |
Heinrich Schuchardt | 06feb5d | 2017-11-10 19:15:02 +0100 | [diff] [blame] | 57 | coccilib.report.print_report(p[0], msg) |