Merge tag 'cocci-7.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jlawall/linux

Pull Coccinelle updates from Julia Lawall:

 - Clean up a number of the semantic patches in the scripts/coccinelle
   directory, particularly with respect to functions that no longer
   exist in the kernel (Sang-Heon Jeon)

   He and I have also done some reorganizations that improve
   performance.

 - Eliminate some false positives (me)

 - Fix an out of date URL (相浦彰)

* tag 'cocci-7.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jlawall/linux:
  coccinelle: ifnulldev_put: update error message
  coccinelle: ifnulldev_put: update outdated helper names
  coccinelle: atomic_as_refcounter: drop atomic_long_dec_and_lock
  coccinelle: kfree_mismatch: drop vmalloc_exec
  coccinelle: pool_zalloc-simple: drop the pci_pool_alloc rules
  coccinelle: zalloc-simple: drop the kmem_alloc rules
  coccinelle: alloc_cast: drop removed allocators
  coccinelle: remove obsolete pci_free_consistent.cocci
  scripts: coccinelle: devm_free: reduce false positives
  coccinelle: misc: struct_size: drop unneeded parentheses
  coccinelle: mini_lock: improve performance when searching loops
  coccinelle: api: check for macro context
  coccinelle: update Coccinelle website URL
  coccinelle: misc: minmax: avoid unhelpful isomorphisms
  coccinelle: misc: minmax: check for the presence of if cases
  coccinelle: misc: minmax: drop unneeded parentheses
  coccinelle: misc: minmax: improve performance when no candidate exists
  coccinelle: double_lock: improve performance when no double lock exists
This commit is contained in:
Linus Torvalds
2026-08-30 10:42:40 -07:00
15 changed files with 149 additions and 164 deletions

View File

@@ -11,7 +11,7 @@ DIR="$(dirname $(readlink -f $0))/.."
SPATCH="`which ${SPATCH:=spatch}`"
if [ ! -x "$SPATCH" ]; then
echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/'
echo 'spatch is part of the Coccinelle project and is available at https://coccinelle.gitlabpages.inria.fr/website'
exit 1
fi
@@ -229,7 +229,7 @@ coccinelle () {
echo " in $FILE."
echo ''
echo ' More information about semantic patching is available at'
echo ' http://coccinelle.lip6.fr/'
echo ' https://coccinelle.gitlabpages.inria.fr/website'
echo ''
if [ "`sed -ne 's|^//#||p' $COCCI`" ] ; then

View File

@@ -20,6 +20,24 @@ virtual patch
virtual org
virtual report
@m1@
identifier i;
expression e;
type T;
position p1;
@@
#define i (T@p1 *)e
@m2@
identifier i;
expression e;
type T;
position p2;
@@
#define i(...) (T@p2 *)e
@initialize:python@
@@
import re
@@ -28,15 +46,15 @@ m = re.compile(pattern)
@r1 depends on context || patch@
type T;
position p != {m1.p1,m2.p2};
@@
(T *)
(T@p *)
\(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|
kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\|vmalloc\|vzalloc\|
dma_alloc_coherent\|devm_kmalloc\|devm_kzalloc\|
kvmalloc\|kvzalloc\|kvmalloc_node\|kvzalloc_node\|pci_alloc_consistent\|
pci_zalloc_consistent\|kmem_alloc\|kmem_zalloc\|kmem_zone_alloc\|
kmem_zone_zalloc\|vmalloc_node\|vzalloc_node\)(...)
kvmalloc\|kvzalloc\|kvmalloc_node\|kvzalloc_node\|
vmalloc_node\|vzalloc_node\)(...)
//----------------------------------------------------------
// For context mode
@@ -57,9 +75,8 @@ type r1.T;
\(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|
kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\|vmalloc\|vzalloc\|
dma_alloc_coherent\|devm_kmalloc\|devm_kzalloc\|
kvmalloc\|kvzalloc\|kvmalloc_node\|kvzalloc_node\|pci_alloc_consistent\|
pci_zalloc_consistent\|kmem_alloc\|kmem_zalloc\|kmem_zone_alloc\|
kmem_zone_zalloc\|vmalloc_node\|vzalloc_node\)(...)
kvmalloc\|kvzalloc\|kvmalloc_node\|kvzalloc_node\|
vmalloc_node\|vzalloc_node\)(...)
//----------------------------------------------------------
// For patch mode
@@ -80,9 +97,8 @@ type r1.T;
\(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|
kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\|vmalloc\|vzalloc\|
dma_alloc_coherent\|devm_kmalloc\|devm_kzalloc\|
kvmalloc\|kvzalloc\|kvmalloc_node\|kvzalloc_node\|pci_alloc_consistent\|
pci_zalloc_consistent\|kmem_alloc\|kmem_zalloc\|kmem_zone_alloc\|
kmem_zone_zalloc\|vmalloc_node\|vzalloc_node\)(...)
kvmalloc\|kvzalloc\|kvmalloc_node\|kvzalloc_node\|
vmalloc_node\|vzalloc_node\)(...)
//----------------------------------------------------------
// For org and report mode
@@ -90,16 +106,15 @@ type r1.T;
@r2 depends on org || report@
type T;
position p;
position p != {m1.p1,m2.p2};
@@
(T@p *)
\(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|
kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\|vmalloc\|vzalloc\|
dma_alloc_coherent\|devm_kmalloc\|devm_kzalloc\|
kvmalloc\|kvzalloc\|kvmalloc_node\|kvzalloc_node\|pci_alloc_consistent\|
pci_zalloc_consistent\|kmem_alloc\|kmem_zalloc\|kmem_zone_alloc\|
kmem_zone_zalloc\|vmalloc_node\|vzalloc_node\)(...)
kvmalloc\|kvzalloc\|kvmalloc_node\|kvzalloc_node\|
vmalloc_node\|vzalloc_node\)(...)
@script:python depends on org@
p << r2.p;

View File

@@ -5,7 +5,7 @@
// Copyright: (C) 2015 Intel Corp.
// Options: --no-includes --include-headers
//
// Keywords: dma_pool_zalloc, pci_pool_zalloc
// Keywords: dma_pool_zalloc
//
virtual context
@@ -22,7 +22,7 @@ expression x;
statement S;
@@
* x = \(dma_pool_alloc\|pci_pool_alloc\)(...);
* x = dma_pool_alloc(...);
if ((x==NULL) || ...) S
* memset(x,0, ...);
@@ -41,17 +41,6 @@ statement S;
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
//----------------------------------------------------------
@@ -63,7 +52,7 @@ statement S;
position p;
@@
x = @p\(dma_pool_alloc\|pci_pool_alloc\)(a,b,c);
x =@p dma_pool_alloc(a,b,c);
if ((x==NULL) || ...) S
memset(x,0, ...);

View File

@@ -35,7 +35,7 @@ statement S;
@@
* x = (T)\(kmalloc(E1, ...)\|vmalloc(E1)\|dma_alloc_coherent(...,E1,...)\|
kmalloc_node(E1, ...)\|kmem_cache_alloc(...)\|kmem_alloc(E1, ...)\|
kmalloc_node(E1, ...)\|kmem_cache_alloc(...)\|
devm_kmalloc(...,E1,...)\|kvmalloc(E1, ...)\|kvmalloc_node(E1,...)\);
if ((x==NULL) || ...) S
* memset((T2)x,0,E1);
@@ -88,15 +88,6 @@ statement S;
- x = (T)kmem_cache_alloc(E3,E4);
+ x = (T)kmem_cache_zalloc(E3,E4);
|
- x = kmem_alloc(E1,E2);
+ x = kmem_zalloc(E1,E2);
|
- x = (T *)kmem_alloc(E1,E2);
+ x = kmem_zalloc(E1,E2);
|
- x = (T)kmem_alloc(E1,E2);
+ x = (T)kmem_zalloc(E1,E2);
|
- x = devm_kmalloc(E2,E1,E3);
+ x = devm_kzalloc(E2,E1,E3);
|
@@ -290,36 +281,6 @@ x << r4.x;
msg="WARNING: kmem_cache_zalloc should be used for %s, instead of kmem_cache_alloc/memset" % (x)
coccilib.report.print_report(p[0], msg)
//-----------------------------------------------------------------
@r5 depends on org || report@
type T, T2;
expression x;
expression E1,E2;
statement S;
position p;
@@
x = (T)kmem_alloc@p(E1,E2);
if ((x==NULL) || ...) S
memset((T2)x,0,E1);
@script:python depends on org@
p << r5.p;
x << r5.x;
@@
msg="%s" % (x)
msg_safe=msg.replace("[","@(").replace("]",")")
coccilib.org.print_todo(p[0], msg_safe)
@script:python depends on report@
p << r5.p;
x << r5.x;
@@
msg="WARNING: kmem_zalloc should be used for %s, instead of kmem_alloc/memset" % (x)
coccilib.report.print_report(p[0], msg)
//-----------------------------------------------------------------
@r6 depends on org || report@
type T, T2;

View File

@@ -26,8 +26,6 @@ identifier fname6 =~ ".*call_rcu.*";
atomic_dec_and_test@p1(&(a)->x)
|
atomic_dec_and_lock@p1(&(a)->x, ...)
|
atomic_long_dec_and_lock@p1(&(a)->x, ...)
|
atomic_long_dec_and_test@p1(&(a)->x)
|
@@ -69,8 +67,6 @@ identifier fname =~ ".*free.*";
atomic_dec_and_test@p1(&(a)->x)
|
atomic_dec_and_lock@p1(&(a)->x, ...)
|
atomic_long_dec_and_lock@p1(&(a)->x, ...)
|
atomic_long_dec_and_test@p1(&(a)->x)
|

View File

@@ -29,7 +29,7 @@ position kok, vok;
} else {
...
E = \(vmalloc\|vzalloc\|vmalloc_user\|vmalloc_node\|
vzalloc_node\|vmalloc_exec\|vmalloc_32\|
vzalloc_node\|vmalloc_32\|
vmalloc_32_user\|__vmalloc\|__vmalloc_node_range\|
__vmalloc_node\)(...)@vok
...
@@ -42,7 +42,7 @@ position kok, vok;
if (E == NULL) {
...
E = \(vmalloc\|vzalloc\|vmalloc_user\|vmalloc_node\|
vzalloc_node\|vmalloc_exec\|vmalloc_32\|
vzalloc_node\|vmalloc_32\|
vmalloc_32_user\|__vmalloc\|__vmalloc_node_range\|
__vmalloc_node\)(...)@vok
...
@@ -68,7 +68,7 @@ position f != free.fok;
* E = \(kmalloc\|kzalloc\|krealloc\|kcalloc\|kmalloc_node\|
* kzalloc_node\|kmalloc_array\|kmalloc_array_node\|
* kcalloc_node\)(...)@a
... when != if (...) { ... E = \(vmalloc\|vzalloc\|vmalloc_user\|vmalloc_node\|vzalloc_node\|vmalloc_exec\|vmalloc_32\|vmalloc_32_user\|__vmalloc\|__vmalloc_node_range\|__vmalloc_node\)(...); ... }
... when != if (...) { ... E = \(vmalloc\|vzalloc\|vmalloc_user\|vmalloc_node\|vzalloc_node\|vmalloc_32\|vmalloc_32_user\|__vmalloc\|__vmalloc_node_range\|__vmalloc_node\)(...); ... }
when != is_vmalloc_addr(E)
when any
* \(vfree\|vfree_atomic\|kvfree\)(E)@f
@@ -82,7 +82,7 @@ position f != free.fok;
E = \(kmalloc\|kzalloc\|krealloc\|kcalloc\|kmalloc_node\|
kzalloc_node\|kmalloc_array\|kmalloc_array_node\|
kcalloc_node\)(...)@a
... when != if (...) { ... E = \(vmalloc\|vzalloc\|vmalloc_user\|vmalloc_node\|vzalloc_node\|vmalloc_exec\|vmalloc_32\|vmalloc_32_user\|__vmalloc\|__vmalloc_node_range\|__vmalloc_node\)(...); ... }
... when != if (...) { ... E = \(vmalloc\|vzalloc\|vmalloc_user\|vmalloc_node\|vzalloc_node\|vmalloc_32\|vmalloc_32_user\|__vmalloc\|__vmalloc_node_range\|__vmalloc_node\)(...); ... }
when != is_vmalloc_addr(E)
when any
- \(vfree\|vfree_atomic\|kvfree\)(E)@f
@@ -95,7 +95,7 @@ position f != free.fok;
@@
* E = \(vmalloc\|vzalloc\|vmalloc_user\|vmalloc_node\|vzalloc_node\|
* vmalloc_exec\|vmalloc_32\|vmalloc_32_user\|__vmalloc\|
* vmalloc_32\|vmalloc_32_user\|__vmalloc\|
* __vmalloc_node_range\|__vmalloc_node\)(...)@a
... when != is_vmalloc_addr(E)
when any
@@ -108,7 +108,7 @@ position f != free.fok;
@@
E = \(vmalloc\|vzalloc\|vmalloc_user\|vmalloc_node\|vzalloc_node\|
vmalloc_exec\|vmalloc_32\|vmalloc_32_user\|__vmalloc\|
vmalloc_32\|vmalloc_32_user\|__vmalloc\|
__vmalloc_node_range\|__vmalloc_node\)(...)@a
... when != is_vmalloc_addr(E)
when any

View File

@@ -26,7 +26,8 @@ virtual report
virtual context
@r depends on context || org || report@
expression x;
type T;
T x;
@@
(
@@ -56,18 +57,26 @@ expression x;
)
@safe depends on context || org || report exists@
expression x;
r.T x;
position p;
@@
(
x = kmalloc(...)
|
x = kmalloc_obj(...)
|
x = kmalloc_objs(...)
|
x = kvasprintf(...)
|
x = kasprintf(...)
|
x = kzalloc(...)
|
x = kzalloc_obj(...)
|
x = kzalloc_objs(...)
|
x = kmalloc_array(...)
|
@@ -105,7 +114,7 @@ position p;
)
@pb@
expression r.x;
r.T r.x;
position p != safe.p;
@@

View File

@@ -23,13 +23,13 @@ expression E;
|
dev_put(E);
|
dev_put_track(E, ...);
netdev_put(E, ...);
|
__dev_hold(E);
|
dev_hold(E);
|
dev_hold_track(E, ...);
netdev_hold(E, ...);
)
@r depends on context || report || org @
@@ -38,18 +38,18 @@ position p;
@@
* if (E != NULL)
* \(__dev_put@p\|dev_put@p\|dev_put_track@p\|__dev_hold@p\|dev_hold@p\|
* dev_hold_track@p\)(E, ...);
* \(__dev_put@p\|dev_put@p\|netdev_put@p\|__dev_hold@p\|dev_hold@p\|
* netdev_hold@p\)(E, ...);
@script:python depends on org@
p << r.p;
@@
cocci.print_main("NULL check before dev_{put, hold} functions is not needed", p)
cocci.print_main("NULL check before (net)dev_{put, hold} functions is not needed", p)
@script:python depends on report@
p << r.p;
@@
msg = "WARNING: NULL check before dev_{put, hold} functions is not needed."
msg = "WARNING: NULL check before (net)dev_{put, hold} functions is not needed."
coccilib.report.print_report(p[0], msg)

View File

@@ -1,53 +0,0 @@
// SPDX-License-Identifier: GPL-2.0-only
/// Find missing pci_free_consistent for every pci_alloc_consistent.
///
// Confidence: Moderate
// Copyright: (C) 2013 Petr Strnad.
// URL: https://coccinelle.gitlabpages.inria.fr/website
// Keywords: pci_free_consistent, pci_alloc_consistent
// Options: --no-includes --include-headers
virtual report
virtual org
@search@
local idexpression id;
expression x,y,z,e;
position p1,p2;
type T;
@@
id = pci_alloc_consistent@p1(x,y,&z)
... when != e = id
if (id == NULL || ...) { ... return ...; }
... when != pci_free_consistent(x,y,id,z)
when != if (id) { ... pci_free_consistent(x,y,id,z) ... }
when != if (y) { ... pci_free_consistent(x,y,id,z) ... }
when != e = (T)id
when exists
(
return 0;
|
return 1;
|
return id;
|
return@p2 ...;
)
@script:python depends on report@
p1 << search.p1;
p2 << search.p2;
@@
msg = "ERROR: missing pci_free_consistent; pci_alloc_consistent on line %s and return without freeing on line %s" % (p1[0].line,p2[0].line)
coccilib.report.print_report(p2[0],msg)
@script:python depends on org@
p1 << search.p1;
p2 << search.p2;
@@
msg = "ERROR: missing pci_free_consistent; pci_alloc_consistent on line %s and return without freeing on line %s" % (p1[0].line,p2[0].line)
cocci.print_main(msg,p1)
cocci.print_secs("",p2)

View File

@@ -38,7 +38,20 @@ write_lock@p1
write_trylock@p1
) (E1@p,...);
@balanced@
@r_candidate exists@
expression x <= locked.E1;
expression locked.E1;
expression E2;
identifier lock;
position locked.p,p1,p2;
@@
lock@p1 (E1@p,...);
... when != E1
when != \(x = E2\|&x\)
lock@p2 (E1,...);
@balanced depends on r_candidate@
position p1 != locked.p1;
position locked.p;
identifier lock,unlock;

View File

@@ -53,11 +53,31 @@ spin_lock_irq@p1
spin_lock_irqsave@p1
) (E1@p,...);
@looped@
@err_candidate exists@
expression E1;
position prelocked.p;
position up != prelocked.p1;
position rc;
identifier lock,unlock;
@@
lock(E1@p,...);
... when != E1
when any
if (...) {
... when != E1
return@rc ...;
}
... when != E1
when any
unlock@up(E1,...);
@looped exists@
position err_candidate.rc;
position r;
@@
for(...;...;...) { <+... return@r ...; ...+> }
for(...;...;...) { <+... return@rc@r ...; ...+> }
@err exists@
expression E1;

View File

@@ -17,7 +17,21 @@ virtual org
virtual context
virtual patch
@rmax depends on !patch@
@max_candidate disable not_int1, not_int2, neg_if_exp@
expression E1, E2, E3, E4;
binary operator cmp = {>, >=};
@@
E1 cmp E2 ? E3 : E4
@min_candidate disable not_int1, not_int2, neg_if_exp@
expression E1, E2, E3, E4;
binary operator cmp = {<, <=};
@@
E1 cmp E2 ? E3 : E4
@rmax depends on !patch && max_candidate disable not_int1, not_int2, neg_if_exp@
identifier func;
expression x, y;
binary operator cmp = {>, >=};
@@ -27,11 +41,23 @@ position p;
func(...)
{
<...
* ((x) cmp@p (y) ? (x) : (y))
* (x) cmp@p (y) ? (x) : (y)
...>
}
@rmaxif depends on !patch@
@maxif_candidate disable not_int1, not_int2, neg_if@
expression x, y;
expression max_val;
binary operator cmp = {>, >=};
@@
if ((x) cmp (y)) {
max_val = (x);
} else {
max_val = (y);
}
@rmaxif depends on !patch && maxif_candidate disable not_int1, not_int2, neg_if@
identifier func;
expression x, y;
expression max_val;
@@ -51,7 +77,7 @@ func(...)
}
// Ignore errcode returns.
@errcode@
@errcode depends on min_candidate disable not_int1, not_int2, neg_if_exp@
position p;
identifier func;
expression x;
@@ -65,7 +91,7 @@ func(...)
...>
}
@rmin depends on !patch@
@rmin depends on !patch && min_candidate disable not_int1, not_int2, neg_if_exp@
identifier func;
expression x, y;
binary operator cmp = {<, <=};
@@ -75,11 +101,23 @@ position p != errcode.p;
func(...)
{
<...
* ((x) cmp@p (y) ? (x) : (y))
* (x) cmp@p (y) ? (x) : (y)
...>
}
@rminif depends on !patch@
@minif_candidate disable not_int1, not_int2, neg_if@
expression x, y;
expression min_val;
binary operator cmp = {<, <=};
@@
if ((x) cmp (y)) {
min_val = (x);
} else {
min_val = (y);
}
@rminif depends on !patch && minif_candidate disable not_int1, not_int2, neg_if@
identifier func;
expression x, y;
expression min_val;
@@ -98,7 +136,7 @@ func(...)
...>
}
@pmax depends on patch@
@pmax depends on patch && max_candidate disable not_int1, not_int2, neg_if_exp@
identifier func;
expression x, y;
binary operator cmp = {>=, >};
@@ -112,7 +150,7 @@ func(...)
...>
}
@pmaxif depends on patch@
@pmaxif depends on patch && maxif_candidate disable not_int1, not_int2, neg_if@
identifier func;
expression x, y;
expression max_val;
@@ -131,7 +169,7 @@ func(...)
...>
}
@pmin depends on patch@
@pmin depends on patch && min_candidate disable not_int1, not_int2, neg_if_exp@
identifier func;
expression x, y;
binary operator cmp = {<=, <};
@@ -146,7 +184,7 @@ func(...)
...>
}
@pminif depends on patch@
@pminif depends on patch && minif_candidate disable not_int1, not_int2, neg_if@
identifier func;
expression x, y;
expression min_val;

View File

@@ -29,9 +29,7 @@ f
expression E1, E2;
identifier m;
@@
(
* (sizeof(*E1) + (E2 * sizeof(*E1->m)))
)
* sizeof(*E1) + (E2 * sizeof(*E1->m))
//----------------------------------------------------------
// For patch mode
@@ -55,9 +53,7 @@ expression E1, E2;
identifier m;
position p;
@@
(
(sizeof(*E1)@p + (E2 * sizeof(*E1->m)))
)
sizeof(*E1)@p + (E2 * sizeof(*E1->m))
@script:python depends on org@
p << r.p;

View File

@@ -8,7 +8,7 @@ SPATCH_REQ_VERSION="1.0.4"
DIR="$(dirname $(readlink -f $0))/.."
SPATCH="`which ${SPATCH:=spatch}`"
if [ ! -x "$SPATCH" ]; then
echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/'
echo 'spatch is part of the Coccinelle project and is available at https://coccinelle.gitlabpages.inria.fr/website'
exit 1
fi