Skip to contentSkip to conversation

coccinelle: misc: minmax: suppress patch generation for err returns

PATCH RESEND In review Denis Efremov 1 participant 2 messages Apr 28, 2021 – Jun 15, 2021 Coccinelle/Semantic Patches (SmPL)

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 coccinelle: misc: minmax: suppress patch generation for err returns

There is a standard idiom for "if 'ret' holds an error, return it":

	return ret < 0 ? ret : 0;

Developers prefer to keep the things as they are because stylistic change to "return min(ret, 0);" breaks readability.

Let's suppress automatic generation for this type of patches.

---
 scripts/coccinelle/misc/minmax.cocci | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
scripts/coccinelle/misc/minmax.cocci +17 -1
index eccdd3eb3452..fcf908b34f27 100644
@@ -116,16 +116,32 @@ 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;
 binary operator cmp = {<=, <};
+position p != errcode.p;
 @@
 
 func(...)
 {
 	<...
--	((x) cmp (y) ? (x) : (y))
+-	((x) cmp@p (y) ? (x) : (y))
 +	min(x, y)
 	...>
 }
Signature · 1 line
2.30.2
#1 lore raw

Ping?

Quoted 52 lines · Denis Efremov

There is a standard idiom for "if 'ret' holds an error, return it":

	return ret < 0 ? ret : 0;

Developers prefer to keep the things as they are because stylistic change to "return min(ret, 0);" breaks readability.

Let's suppress automatic generation for this type of patches.

---
 scripts/coccinelle/misc/minmax.cocci | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
scripts/coccinelle/misc/minmax.cocci +17 -1
index eccdd3eb3452..fcf908b34f27 100644
@@ -116,16 +116,32 @@ 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;
 binary operator cmp = {<=, <};
+position p != errcode.p;
 @@
 
 func(...)
 {
 	<...
--	((x) cmp (y) ? (x) : (y))
+-	((x) cmp@p (y) ? (x) : (y))
 +	min(x, y)
 	...>
 }