[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.DEB.2.22.394.2102172208030.3081@hadrien>
Date: Wed, 17 Feb 2021 22:17:56 +0100 (CET)
From: Julia Lawall <julia.lawall@...ia.fr>
To: Denis Efremov <efremov@...ux.com>
cc: Julia Lawall <julia.lawall@...ia.fr>, cocci@...teme.lip6.fr,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] coccinelle: misc: add minmax script
On Tue, 16 Feb 2021, Denis Efremov wrote:
> Check for opencoded min(), max() implementations.
Some cases that could be improved:
diff -u -p a/drivers/platform/x86/asus-laptop.c
b/drivers/platform/x86/asus-laptop.c
--- a/drivers/platform/x86/asus-laptop.c
+++ b/drivers/platform/x86/asus-laptop.c
@@ -1195,7 +1195,7 @@ static ssize_t ls_level_store(struct dev
if (rv < 0)
return rv;
- value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
+ value = (0 < value) ? (min(15, value)) : 0;
/* 0 <= value <= 15 */
asus_als_level(asus, value);
diff -u -p a/sound/pci/ctxfi/ctatc.c b/sound/pci/ctxfi/ctatc.c
--- a/sound/pci/ctxfi/ctatc.c
+++ b/sound/pci/ctxfi/ctatc.c
@@ -382,7 +382,7 @@ static int atc_pcm_playback_start(struct
apcm->started = 1;
max_cisz = src->multi * src->rsc.msr;
- max_cisz = 0x80 * (max_cisz < 8 ? max_cisz : 8);
+ max_cisz = 0x80 * (min(max_cisz, 8));
> +func(...)
> +{
> + ... when any
> +* (x cmp y) ?@p x : y
> + ... when any
> +}
In all cases, this would be more efficient as:
func(...)
{
<...
* (x cmp y) ?@p x : y
...>
}
There is an optimization that causes this to be just a search through the
nodes of the control-flow graph, rather than following the actual control
flow from the beginning of the function to the end.
> +@...ipt:python depends on report@
> +p << rmax.p;
> +@@
> +
> +coccilib.report.print_report(p[0], "WARNING opportunity for max()")
> +
> +@...ipt:python depends on org@
> +p << rmax.p;
> +@@
> +
> +coccilib.report.print_todo(p[0], "WARNING opportunity for max()")
All of the org cases should be coccilib.org, not coccilib.report.
julia
Powered by blists - more mailing lists