* [PATCH] coccinelle: misc: minmax: suppress patch generation for err returns
@ 2021-04-09 11:19 Denis Efremov
2021-04-22 7:21 ` Denis Efremov
0 siblings, 1 reply; 2+ messages in thread
From: Denis Efremov @ 2021-04-09 11:19 UTC (permalink / raw)
To: julia.lawall; +Cc: Denis Efremov, cocci, linux-kernel
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.
Signed-off-by: Denis Efremov <efremov@linux.com>
---
scripts/coccinelle/misc/minmax.cocci | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/scripts/coccinelle/misc/minmax.cocci b/scripts/coccinelle/misc/minmax.cocci
index eccdd3eb3452..fcf908b34f27 100644
--- a/scripts/coccinelle/misc/minmax.cocci
+++ b/scripts/coccinelle/misc/minmax.cocci
@@ -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)
...>
}
--
2.30.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] coccinelle: misc: minmax: suppress patch generation for err returns
2021-04-09 11:19 [PATCH] coccinelle: misc: minmax: suppress patch generation for err returns Denis Efremov
@ 2021-04-22 7:21 ` Denis Efremov
0 siblings, 0 replies; 2+ messages in thread
From: Denis Efremov @ 2021-04-22 7:21 UTC (permalink / raw)
To: julia.lawall; +Cc: cocci, linux-kernel
Ping?
On 4/9/21 2:19 PM, Denis Efremov wrote:
> 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.
>
> Signed-off-by: Denis Efremov <efremov@linux.com>
> ---
> scripts/coccinelle/misc/minmax.cocci | 18 +++++++++++++++++-
> 1 file changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/coccinelle/misc/minmax.cocci b/scripts/coccinelle/misc/minmax.cocci
> index eccdd3eb3452..fcf908b34f27 100644
> --- a/scripts/coccinelle/misc/minmax.cocci
> +++ b/scripts/coccinelle/misc/minmax.cocci
> @@ -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)
> ...>
> }
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-04-22 7:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-09 11:19 [PATCH] coccinelle: misc: minmax: suppress patch generation for err returns Denis Efremov
2021-04-22 7:21 ` Denis Efremov
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.