Skip to contentSkip to conversation

coccinelle: misc: minmax: Suppress reports for err returns

PATCH Applied Ricardo Ribalda 3 participants 10 messages Apr 15, 2024 – Apr 19, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 coccinelle: misc: minmax: Suppress reports for err returns

Most of the people prefer:

return ret < 0 ? ret: 0;

than:

return min(ret, 0);

Let's tweak the cocci file to ignore those lines completely.

---
Following discussion at:
https://lore.kernel.org/linux-media/[email protected]/T/#m4dce34572312bd8a02542d798f21af7e4fc05fe8

---
 scripts/coccinelle/misc/minmax.cocci | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)
scripts/coccinelle/misc/minmax.cocci +16 -16
index fcf908b34f27..ca4830ae3042 100644
@@ -50,11 +50,26 @@ func(...)
 	...>
 }
 
+// Ignore errcode returns.
+@errcode@
+position p;
+identifier func;
+expression x;
+binary operator cmp = {<, <=};
+@@
+
+func(...)
+{
+	<...
+	return ((x) cmp@p 0 ? (x) : 0);
+	...>
+}
+
 @rmin depends on !patch@
 identifier func;
 expression x, y;
 binary operator cmp = {<, <=};
-position p;
+position p != errcode.p;
 @@
 
 func(...)
@@ -116,21 +131,6 @@ func(...)
 	...>
 }
 
-// Don't generate patches for errcode returns.
-@errcode depends on patch@
-position p;
-identifier func;
-expression x;
-binary operator cmp = {<, <=};
-@@
-
-func(...)
-{
-	<...
-	return ((x) cmp@p 0 ? (x) : 0);
-	...>
-}
-
 @pmin depends on patch@
 identifier func;
 expression x, y;

---
base-commit: 71b3ed53b08d87212fbbe51bdc3bf44eb8c462f8
change-id: 20240415-minimax-1e9110d4697b

Best regards,

Signature · 1 line
Ricardo Ribalda <[email protected]>
maintainer
#1 lore raw
Quoted 11 lines · Ricardo Ribalda

Most of the people prefer:

return ret < 0 ? ret: 0;

than:

return min(ret, 0);

Let's tweak the cocci file to ignore those lines completely.

I agree. Thanks for the patch.

julia

Quoted 71 lines

---
Following discussion at:
https://lore.kernel.org/linux-media/[email protected]/T/#m4dce34572312bd8a02542d798f21af7e4fc05fe8

---
 scripts/coccinelle/misc/minmax.cocci | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)
scripts/coccinelle/misc/minmax.cocci +16 -17
index fcf908b34f27..ca4830ae3042 100644
@@ -50,11 +50,26 @@ func(...)
 	...>
 }
 
+// Ignore errcode returns.
+@errcode@
+position p;
+identifier func;
+expression x;
+binary operator cmp = {<, <=};
+@@
+
+func(...)
+{
+	<...
+	return ((x) cmp@p 0 ? (x) : 0);
+	...>
+}
+
 @rmin depends on !patch@
 identifier func;
 expression x, y;
 binary operator cmp = {<, <=};
-position p;
+position p != errcode.p;
 @@
 
 func(...)
@@ -116,21 +131,6 @@ func(...)
 	...>
 }
 
-// Don't generate patches for errcode returns.
-@errcode depends on patch@
-position p;
-identifier func;
-expression x;
-binary operator cmp = {<, <=};
-@@
-
-func(...)
-{
-	<...
-	return ((x) cmp@p 0 ? (x) : 0);
-	...>
-}
-
 @pmin depends on patch@
 identifier func;
 expression x, y;
 
---

base-commit: 71b3ed53b08d87212fbbe51bdc3bf44eb8c462f8
change-id: 20240415-minimax-1e9110d4697b

Best regards,
--
Ricardo Ribalda <[email protected]>

#2 lore raw
In reply to Ricardo Ribalda

…

scripts/coccinelle/misc/minmax.cocci func(...) · line 54

Quoted 7 lines

+++ b/scripts/coccinelle/misc/minmax.cocci

scripts/coccinelle/misc/minmax.cocci +2 -0
@@ -50,11 +50,26 @@ func(...)
 	...>
 }
 
+// Ignore errcode returns.
+@errcode@

…

I see that you would like to omit the specification “depends on patch” from the previous SmPL rule location.

Would you really like to influence and adjust SmPL code any more according to affected coccicheck operation modes?

Regards,
Markus

#3 lore raw

Hi Markus

Quoted 11 lines · Markus Elfring

…

Quoted 7 lines

+++ b/scripts/coccinelle/misc/minmax.cocci

scripts/coccinelle/misc/minmax.cocci +2 -0
@@ -50,11 +50,26 @@ func(...)
      ...>
 }
 
+// Ignore errcode returns.
+@errcode@

…

Quoted 5 lines

I see that you would like to omit the specification “depends on patch” from the previous SmPL rule location.

Would you really like to influence and adjust SmPL code any more according to affected coccicheck operation modes?

I probably do not know what I am doing :), it is my first .cocci patch.

If I leave the "depends on patch", then the change is ignored in report mode.

I think errcode needs to be executed in report and in patch mode, but there might be a better way to do it.

Quoted 3 lines

Regards,
Markus

Signature · 1 line
Ricardo Ribalda
#4 lore raw
Quoted 1 line

I think errcode needs to be executed in report and in patch mode,

Adjustments for functionality of coccicheck operation modes can be clarified further.

Quoted 1 line

but there might be a better way to do it.

Corresponding design options depend on varying development efforts and resources.

Regards,
Markus

#5 lore raw

Hi "Markus"

Quoted 4 lines · Markus Elfring
Quoted 2 lines

I think errcode needs to be executed in report and in patch mode,

Adjustments for functionality of coccicheck operation modes can be clarified further.

https://lore.kernel.org/lkml/2024041643-unshaven-happiest-1405@gregkh/

Quoted 8 lines
Quoted 3 lines

but there might be a better way to do it.

Corresponding design options depend on varying development efforts and resources.

Regards,
Markus

Signature · 1 line
Ricardo Ribalda
maintainer Applied
#7 lore raw
In reply to Ricardo Ribalda
Quoted 11 lines · Ricardo Ribalda

Most of the people prefer:

return ret < 0 ? ret: 0;

than:

return min(ret, 0);

Let's tweak the cocci file to ignore those lines completely.

Applied, thanks. (Coccinelle for-6.10 branch).

julia

Quoted 71 lines

---
Following discussion at:
https://lore.kernel.org/linux-media/[email protected]/T/#m4dce34572312bd8a02542d798f21af7e4fc05fe8

---
 scripts/coccinelle/misc/minmax.cocci | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)
scripts/coccinelle/misc/minmax.cocci +16 -17
index fcf908b34f27..ca4830ae3042 100644
@@ -50,11 +50,26 @@ func(...)
 	...>
 }
 
+// Ignore errcode returns.
+@errcode@
+position p;
+identifier func;
+expression x;
+binary operator cmp = {<, <=};
+@@
+
+func(...)
+{
+	<...
+	return ((x) cmp@p 0 ? (x) : 0);
+	...>
+}
+
 @rmin depends on !patch@
 identifier func;
 expression x, y;
 binary operator cmp = {<, <=};
-position p;
+position p != errcode.p;
 @@
 
 func(...)
@@ -116,21 +131,6 @@ func(...)
 	...>
 }
 
-// Don't generate patches for errcode returns.
-@errcode depends on patch@
-position p;
-identifier func;
-expression x;
-binary operator cmp = {<, <=};
-@@
-
-func(...)
-{
-	<...
-	return ((x) cmp@p 0 ? (x) : 0);
-	...>
-}
-
 @pmin depends on patch@
 identifier func;
 expression x, y;
 
---

base-commit: 71b3ed53b08d87212fbbe51bdc3bf44eb8c462f8
change-id: 20240415-minimax-1e9110d4697b

Best regards,
--
Ricardo Ribalda <[email protected]>

#8 lore raw
Quoted 9 lines
Quoted 9 lines

Most of the people prefer:

return ret < 0 ? ret: 0;

than:

return min(ret, 0);

Let's tweak the cocci file to ignore those lines completely.

…

Quoted 1 line

Applied, thanks. (Coccinelle for-6.10 branch).

Was a planned code adjustment published?

…

Quoted 7 lines
Quoted 7 lines

+++ b/scripts/coccinelle/misc/minmax.cocci

scripts/coccinelle/misc/minmax.cocci +2 -0
@@ -50,11 +50,26 @@ func(...)
 	...>
 }
 
+// Ignore errcode returns.
+@errcode@

…

Quoted 2 lines
Quoted 2 lines

-// Don't generate patches for errcode returns.
-@errcode depends on patch@

…

How does such a change fit to the usability of the coccicheck operation modes “context” and “org”?

Should dependencies be reconsidered any more for the desired consistency of involved rules for scripts of the semantic patch language?

Regards,
Markus

maintainer
#9 lore raw
Quoted 6 lines · Markus Elfring
Quoted 6 lines
Quoted 6 lines

Most of the people prefer:

return ret < 0 ? ret: 0;

than:

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

return min(ret, 0);

Let's tweak the cocci file to ignore those lines completely.

…

Quoted 1 line

Applied, thanks. (Coccinelle for-6.10 branch).

Was a planned code adjustment published?

There is no "planned code adjustment" if there is no patch.

I can check the dependencies again.

julia

Quoted 24 lines

…

Quoted 7 lines
Quoted 7 lines

+++ b/scripts/coccinelle/misc/minmax.cocci

scripts/coccinelle/misc/minmax.cocci +2 -0
@@ -50,11 +50,26 @@ func(...)
 	...>
 }
 
+// Ignore errcode returns.
+@errcode@

…

Quoted 2 lines
Quoted 2 lines

-// Don't generate patches for errcode returns.
-@errcode depends on patch@

…

How does such a change fit to the usability of the coccicheck operation modes “context” and “org”?

Should dependencies be reconsidered any more for the desired consistency of involved rules for scripts of the semantic patch language?

Regards,
Markus