summaryrefslogtreecommitdiffstats
path: root/scripts/coccinelle/misc
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2026-08-30 10:42:40 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2026-08-30 10:42:40 -0700
commiteea8bdcb59e02729a33a8666f7b0b5e30e6cb736 (patch)
tree13129668f546c78eb4c64ba97cfa9227c4e60b55 /scripts/coccinelle/misc
parentcbb4c6d9af7dde462f8c9261bdcd35c47a0b4054 (diff)
parentef6a1dca8de41a408019310649e6d1b7b21ac4bc (diff)
downloadlinux-stable-eea8bdcb59e02729a33a8666f7b0b5e30e6cb736.tar.gz
linux-stable-eea8bdcb59e02729a33a8666f7b0b5e30e6cb736.zip
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
Diffstat (limited to 'scripts/coccinelle/misc')
-rw-r--r--scripts/coccinelle/misc/minmax.cocci60
-rw-r--r--scripts/coccinelle/misc/struct_size.cocci8
2 files changed, 51 insertions, 17 deletions
diff --git a/scripts/coccinelle/misc/minmax.cocci b/scripts/coccinelle/misc/minmax.cocci
index ca4830ae3..b83d4a01e 100644
--- a/scripts/coccinelle/misc/minmax.cocci
+++ b/scripts/coccinelle/misc/minmax.cocci
@@ -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;
diff --git a/scripts/coccinelle/misc/struct_size.cocci b/scripts/coccinelle/misc/struct_size.cocci
index 9b02c3743..406884d68 100644
--- a/scripts/coccinelle/misc/struct_size.cocci
+++ b/scripts/coccinelle/misc/struct_size.cocci
@@ -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;