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