diff options
author | Tom Rini <trini@konsulko.com> | 2020-04-25 08:20:22 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2020-04-25 08:20:22 -0400 |
commit | d202f67db0771247de562af5d6a5df778702857b (patch) | |
tree | 7c48f316e008c90e19b54f93e1ede85bfe237fcb /scripts/coccinelle | |
parent | 4d131cdb6762694fc1a66d6b3e39a82f9ec691cf (diff) | |
parent | 691132e850539cb0956a106933d5bde37470bfc7 (diff) |
Merge branch '2020-04-25-master-imports'
- Assorted minor fixes
- Actions S700 SoC and Cubieboard7 support
Diffstat (limited to 'scripts/coccinelle')
-rw-r--r-- | scripts/coccinelle/api/alloc/alloc_cast.cocci | 102 | ||||
-rw-r--r-- | scripts/coccinelle/free/ifnullfree.cocci | 24 |
2 files changed, 113 insertions, 13 deletions
diff --git a/scripts/coccinelle/api/alloc/alloc_cast.cocci b/scripts/coccinelle/api/alloc/alloc_cast.cocci new file mode 100644 index 0000000000..e336784a9f --- /dev/null +++ b/scripts/coccinelle/api/alloc/alloc_cast.cocci @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0-only +/// Remove casting the values returned by memory allocation functions +/// like kmalloc, kzalloc, kmem_cache_alloc, kmem_cache_zalloc etc. +/// +//# This makes an effort to find cases of casting of values returned by +//# malloc, calloc, kmalloc, kmalloc_array, kmalloc_node and removes +//# the casting as it is not required. The result in the patch case may +//# need some reformatting. +// +// Confidence: High +// Copyright: (C) 2014 Himangi Saraogi +// Copyright: (C) 2017 Himanshu Jha +// Comments: +// Options: --no-includes --include-headers +// + +virtual context +virtual patch +virtual org +virtual report + +@initialize:python@ +@@ +import re +pattern = '__' +m = re.compile(pattern) + +@r1 depends on context || patch@ +type T; +@@ + + (T *) + \(malloc\|calloc\|kmalloc\|kmalloc_array\|kmalloc_node\)(...) + +//---------------------------------------------------------- +// For context mode +//---------------------------------------------------------- + +@script:python depends on context@ +t << r1.T; +@@ + +if m.search(t) != None: + cocci.include_match(False) + +@depends on context && r1@ +type r1.T; +@@ + +* (T *) + \(malloc\|calloc\|kmalloc\|kmalloc_array\|kmalloc_node\)(...) + +//---------------------------------------------------------- +// For patch mode +//---------------------------------------------------------- + +@script:python depends on patch@ +t << r1.T; +@@ + +if m.search(t) != None: + cocci.include_match(False) + +@depends on patch && r1@ +type r1.T; +@@ + +- (T *) + \(malloc\|calloc\|kmalloc\|kmalloc_array\|kmalloc_node\)(...) + +//---------------------------------------------------------- +// For org and report mode +//---------------------------------------------------------- + +@r2 depends on org || report@ +type T; +position p; +@@ + + (T@p *) + \(malloc\|calloc\|kmalloc\|kmalloc_array\|kmalloc_node\)(...) + +@script:python depends on org@ +p << r2.p; +t << r2.T; +@@ + +if m.search(t) != None: + cocci.include_match(False) +else: + coccilib.org.print_safe_todo(p[0], t) + +@script:python depends on report@ +p << r2.p; +t << r2.T; +@@ + +if m.search(t) != None: + cocci.include_match(False) +else: + msg="WARNING: casting value returned by memory allocation function to (%s *) is useless." % (t) + coccilib.report.print_report(p[0], msg) diff --git a/scripts/coccinelle/free/ifnullfree.cocci b/scripts/coccinelle/free/ifnullfree.cocci index 14a4cd98e8..2d59545d7d 100644 --- a/scripts/coccinelle/free/ifnullfree.cocci +++ b/scripts/coccinelle/free/ifnullfree.cocci @@ -1,10 +1,11 @@ +// SPDX-License-Identifier: GPL-2.0-only /// 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. /// -// Copyright: (C) 2014 Fabian Frederick. GPLv2. +// Copyright: (C) 2014 Fabian Frederick. // Comments: - // Options: --no-includes --include-headers @@ -18,21 +19,19 @@ expression E; @@ - if (E != NULL) ( - kfree(E); + free(E); | - kzfree(E); + kfree(E); | - debugfs_remove(E); + vfree(E); | - debugfs_remove_recursive(E); + vfree_recursive(E); | - usb_free_urb(E); + kmem_cache_free(E); | kmem_cache_destroy(E); | - mempool_destroy(E); -| - dma_pool_destroy(E); + gzfree(E); ) @r depends on context || report || org @ @@ -41,9 +40,8 @@ position p; @@ * if (E != NULL) -* \(kfree@p\|kzfree@p\|debugfs_remove@p\|debugfs_remove_recursive@p\| -* usb_free_urb@p\|kmem_cache_destroy@p\|mempool_destroy@p\| -* dma_pool_destroy@p\)(E); +* \(free@p\|kfree@p\|vfree@p\|debugfs_remove_recursive@p\| +* kmem_cache_free@p\|kmem_cache_destroy@p\|gzfree@p\)(E); @script:python depends on org@ p << r.p; @@ -55,5 +53,5 @@ cocci.print_main("NULL check before that freeing function is not needed", p) 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." +msg = "WARNING: NULL check before some freeing functions is not needed." coccilib.report.print_report(p[0], msg) |