summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorJulia Lawall <Julia.Lawall@inria.fr>2026-07-26 16:08:56 +0200
committerJulia Lawall <Julia.Lawall@inria.fr>2026-08-23 22:12:10 +0200
commitaf8613c863a3160b7fb6fd09cbf5b56e37330d80 (patch)
tree65c6b047ba7c6e88e89e7813d07ce25a3af03a42 /scripts
parentfd0a63f086b3f2f45c49b1378f6c2ac7a542db19 (diff)
downloadlinux-next-af8613c863a3160b7fb6fd09cbf5b56e37330d80.tar.gz
linux-next-af8613c863a3160b7fb6fd09cbf5b56e37330d80.zip
coccinelle: misc: minmax: check for the presence of if cases
As done previously for the ternary command, check that a file contains the min or max if pattern before applying the minif and maxif rules. Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/coccinelle/misc/minmax.cocci32
1 files changed, 28 insertions, 4 deletions
diff --git a/scripts/coccinelle/misc/minmax.cocci b/scripts/coccinelle/misc/minmax.cocci
index 905dd2292609..f14e608240b6 100644
--- a/scripts/coccinelle/misc/minmax.cocci
+++ b/scripts/coccinelle/misc/minmax.cocci
@@ -45,7 +45,19 @@ func(...)
...>
}
-@rmaxif depends on !patch@
+@maxif_candidate@
+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@
identifier func;
expression x, y;
expression max_val;
@@ -93,7 +105,19 @@ func(...)
...>
}
-@rminif depends on !patch@
+@minif_candidate@
+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@
identifier func;
expression x, y;
expression min_val;
@@ -126,7 +150,7 @@ func(...)
...>
}
-@pmaxif depends on patch@
+@pmaxif depends on patch && maxif_candidate@
identifier func;
expression x, y;
expression max_val;
@@ -160,7 +184,7 @@ func(...)
...>
}
-@pminif depends on patch@
+@pminif depends on patch && maxif_candidate@
identifier func;
expression x, y;
expression min_val;