diff options
Diffstat (limited to 'kernel/scripts/coccinelle/api')
5 files changed, 220 insertions, 3 deletions
diff --git a/kernel/scripts/coccinelle/api/alloc/pool_zalloc-simple.cocci b/kernel/scripts/coccinelle/api/alloc/pool_zalloc-simple.cocci new file mode 100644 index 000000000..9b7eb321a --- /dev/null +++ b/kernel/scripts/coccinelle/api/alloc/pool_zalloc-simple.cocci @@ -0,0 +1,84 @@ +/// +/// Use *_pool_zalloc rather than *_pool_alloc followed by memset with 0 +/// +// Copyright: (C) 2015 Intel Corp. GPLv2. +// Options: --no-includes --include-headers +// +// Keywords: dma_pool_zalloc, pci_pool_zalloc +// + +virtual context +virtual patch +virtual org +virtual report + +//---------------------------------------------------------- +// For context mode +//---------------------------------------------------------- + +@depends on context@ +expression x; +statement S; +@@ + +* x = \(dma_pool_alloc\|pci_pool_alloc\)(...); + if ((x==NULL) || ...) S +* memset(x,0, ...); + +//---------------------------------------------------------- +// For patch mode +//---------------------------------------------------------- + +@depends on patch@ +expression x; +expression a,b,c; +statement S; +@@ + +- x = dma_pool_alloc(a,b,c); ++ x = dma_pool_zalloc(a,b,c); + if ((x==NULL) || ...) S +- memset(x,0,...); + +@depends on patch@ +expression x; +expression a,b,c; +statement S; +@@ + +- x = pci_pool_alloc(a,b,c); ++ x = pci_pool_zalloc(a,b,c); + if ((x==NULL) || ...) S +- memset(x,0,...); + +//---------------------------------------------------------- +// For org and report mode +//---------------------------------------------------------- + +@r depends on org || report@ +expression x; +expression a,b,c; +statement S; +position p; +@@ + + x = @p\(dma_pool_alloc\|pci_pool_alloc\)(a,b,c); + if ((x==NULL) || ...) S + memset(x,0, ...); + +@script:python depends on org@ +p << r.p; +x << r.x; +@@ + +msg="%s" % (x) +msg_safe=msg.replace("[","@(").replace("]",")") +coccilib.org.print_todo(p[0], msg_safe) + +@script:python depends on report@ +p << r.p; +x << r.x; +@@ + +msg="WARNING: *_pool_zalloc should be used for %s, instead of *_pool_alloc/memset" % (x) +coccilib.report.print_report(p[0], msg) diff --git a/kernel/scripts/coccinelle/api/platform_no_drv_owner.cocci b/kernel/scripts/coccinelle/api/platform_no_drv_owner.cocci index e065b9e71..c5e3f73f2 100644 --- a/kernel/scripts/coccinelle/api/platform_no_drv_owner.cocci +++ b/kernel/scripts/coccinelle/api/platform_no_drv_owner.cocci @@ -9,11 +9,14 @@ virtual org virtual report @match1@ +declarer name module_i2c_driver; declarer name module_platform_driver; declarer name module_platform_driver_probe; identifier __driver; @@ ( + module_i2c_driver(__driver); +| module_platform_driver(__driver); | module_platform_driver_probe(__driver, ...); @@ -28,6 +31,15 @@ identifier match1.__driver; } }; +@fix1_i2c depends on match1 && patch && !context && !org && !report@ +identifier match1.__driver; +@@ + static struct i2c_driver __driver = { + .driver = { +- .owner = THIS_MODULE, + } + }; + @match2@ identifier __driver; @@ @@ -37,6 +49,8 @@ identifier __driver; platform_driver_probe(&__driver, ...) | platform_create_bundle(&__driver, ...) +| + i2c_add_driver(&__driver) ) @fix2 depends on match2 && patch && !context && !org && !report@ @@ -48,6 +62,15 @@ identifier match2.__driver; } }; +@fix2_i2c depends on match2 && patch && !context && !org && !report@ +identifier match2.__driver; +@@ + static struct i2c_driver __driver = { + .driver = { +- .owner = THIS_MODULE, + } + }; + // ---------------------------------------------------------------------------- @fix1_context depends on match1 && !patch && (context || org || report)@ @@ -61,6 +84,17 @@ position j0; } }; +@fix1_i2c_context depends on match1 && !patch && (context || org || report)@ +identifier match1.__driver; +position j0; +@@ + + static struct i2c_driver __driver = { + .driver = { +* .owner@j0 = THIS_MODULE, + } + }; + @fix2_context depends on match2 && !patch && (context || org || report)@ identifier match2.__driver; position j0; @@ -72,6 +106,17 @@ position j0; } }; +@fix2_i2c_context depends on match2 && !patch && (context || org || report)@ +identifier match2.__driver; +position j0; +@@ + + static struct i2c_driver __driver = { + .driver = { +* .owner@j0 = THIS_MODULE, + } + }; + // ---------------------------------------------------------------------------- @script:python fix1_org depends on org@ @@ -81,6 +126,13 @@ j0 << fix1_context.j0; msg = "No need to set .owner here. The core will do it." coccilib.org.print_todo(j0[0], msg) +@script:python fix1_i2c_org depends on org@ +j0 << fix1_i2c_context.j0; +@@ + +msg = "No need to set .owner here. The core will do it." +coccilib.org.print_todo(j0[0], msg) + @script:python fix2_org depends on org@ j0 << fix2_context.j0; @@ @@ -88,6 +140,13 @@ j0 << fix2_context.j0; msg = "No need to set .owner here. The core will do it." coccilib.org.print_todo(j0[0], msg) +@script:python fix2_i2c_org depends on org@ +j0 << fix2_i2c_context.j0; +@@ + +msg = "No need to set .owner here. The core will do it." +coccilib.org.print_todo(j0[0], msg) + // ---------------------------------------------------------------------------- @script:python fix1_report depends on report@ @@ -97,6 +156,13 @@ j0 << fix1_context.j0; msg = "No need to set .owner here. The core will do it." coccilib.report.print_report(j0[0], msg) +@script:python fix1_i2c_report depends on report@ +j0 << fix1_i2c_context.j0; +@@ + +msg = "No need to set .owner here. The core will do it." +coccilib.report.print_report(j0[0], msg) + @script:python fix2_report depends on report@ j0 << fix2_context.j0; @@ @@ -104,3 +170,10 @@ j0 << fix2_context.j0; msg = "No need to set .owner here. The core will do it." coccilib.report.print_report(j0[0], msg) +@script:python fix2_i2c_report depends on report@ +j0 << fix2_i2c_context.j0; +@@ + +msg = "No need to set .owner here. The core will do it." +coccilib.report.print_report(j0[0], msg) + diff --git a/kernel/scripts/coccinelle/api/pm_runtime.cocci b/kernel/scripts/coccinelle/api/pm_runtime.cocci index f01789e96..b7042d074 100644 --- a/kernel/scripts/coccinelle/api/pm_runtime.cocci +++ b/kernel/scripts/coccinelle/api/pm_runtime.cocci @@ -1,5 +1,5 @@ /// Make sure pm_runtime_* calls does not use unnecessary IS_ERR_VALUE -// +/// // Keywords: pm_runtime // Confidence: Medium // Copyright (C) 2013 Texas Instruments Incorporated - GPLv2. diff --git a/kernel/scripts/coccinelle/api/simple_open.cocci b/kernel/scripts/coccinelle/api/simple_open.cocci index b67e174f3..bd1a2a4ee 100644 --- a/kernel/scripts/coccinelle/api/simple_open.cocci +++ b/kernel/scripts/coccinelle/api/simple_open.cocci @@ -1,5 +1,5 @@ -/// This removes an open coded simple_open() function -/// and replaces file operations references to the function +/// Remove an open coded simple_open() function +/// and replace file operations references to the function /// with simple_open() instead. /// // Confidence: High diff --git a/kernel/scripts/coccinelle/api/vma_pages.cocci b/kernel/scripts/coccinelle/api/vma_pages.cocci new file mode 100644 index 000000000..3e52e11ea --- /dev/null +++ b/kernel/scripts/coccinelle/api/vma_pages.cocci @@ -0,0 +1,60 @@ +/// +/// Use vma_pages function on vma object instead of explicit computation. +/// +// Confidence: High +// Keywords: vma_pages vma +// Comment: Based on resource_size.cocci + +virtual context +virtual patch +virtual org +virtual report + +//---------------------------------------------------------- +// For context mode +//---------------------------------------------------------- + +@r_context depends on context && !patch && !org && !report@ +struct vm_area_struct *vma; +@@ + +* (vma->vm_end - vma->vm_start) >> PAGE_SHIFT + +//---------------------------------------------------------- +// For patch mode +//---------------------------------------------------------- + +@r_patch depends on !context && patch && !org && !report@ +struct vm_area_struct *vma; +@@ + +- ((vma->vm_end - vma->vm_start) >> PAGE_SHIFT) ++ vma_pages(vma) + +//---------------------------------------------------------- +// For org mode +//---------------------------------------------------------- + +@r_org depends on !context && !patch && (org || report)@ +struct vm_area_struct *vma; +position p; +@@ + + (vma->vm_end@p - vma->vm_start) >> PAGE_SHIFT + +@script:python depends on report@ +p << r_org.p; +x << r_org.vma; +@@ + +msg="WARNING: Consider using vma_pages helper on %s" % (x) +coccilib.report.print_report(p[0], msg) + +@script:python depends on org@ +p << r_org.p; +x << r_org.vma; +@@ + +msg="WARNING: Consider using vma_pages helper on %s" % (x) +msg_safe=msg.replace("[","@(").replace("]",")") +coccilib.org.print_todo(p[0], msg_safe) |