2020-08-21 00:04:12

by Alex Dewar

[permalink] [raw]
Subject: [PATCH] coccinelle: add patch rule for dma_alloc_coherent

Commit dfd32cad146e ("dma-mapping: remove dma_zalloc_coherent()")
removed the definition of dma_zalloc_coherent() and also removed the
corresponding patch rule for replacing instances of dma_alloc_coherent +
memset in zalloc-simple.cocci (though left the report rule).

Add a new patch rule to remove unnecessary calls to memset after
allocating with dma_alloc_coherent. While we're at it, fix a couple of
typos.

Fixes: dfd32cad146e ("dma-mapping: remove dma_zalloc_coherent()")
Signed-off-by: Alex Dewar <[email protected]>
---
scripts/coccinelle/api/alloc/zalloc-simple.cocci | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/scripts/coccinelle/api/alloc/zalloc-simple.cocci b/scripts/coccinelle/api/alloc/zalloc-simple.cocci
index 26cda3f48f01..b3d0c3c230c1 100644
--- a/scripts/coccinelle/api/alloc/zalloc-simple.cocci
+++ b/scripts/coccinelle/api/alloc/zalloc-simple.cocci
@@ -127,6 +127,16 @@ statement S;
if ((x==NULL) || ...) S
- memset((T2)x,0,E1);

+@depends on patch@
+type T, T2;
+expression x;
+expression E1,E2,E3,E4;
+statement S;
+@@
+ x = (T)dma_alloc_coherent(E1, E2, E3, E4);
+ if ((x==NULL) || ...) S
+- memset((T2)x, 0, E2);
+
//----------------------------------------------------------
// For org mode
//----------------------------------------------------------
@@ -199,9 +209,9 @@ statement S;
position p;
@@

- x = (T)dma_alloc_coherent@p(E2,E1,E3,E4);
+ x = (T)dma_alloc_coherent@p(E1,E2,E3,E4);
if ((x==NULL) || ...) S
- memset((T2)x,0,E1);
+ memset((T2)x,0,E2);

@script:python depends on org@
p << r2.p;
@@ -217,7 +227,7 @@ p << r2.p;
x << r2.x;
@@

-msg="WARNING: dma_alloc_coherent use in %s already zeroes out memory, so memset is not needed" % (x)
+msg="WARNING: dma_alloc_coherent used in %s already zeroes out memory, so memset is not needed" % (x)
coccilib.report.print_report(p[0], msg)

//-----------------------------------------------------------------
--
2.28.0


2020-08-21 15:39:13

by Julia Lawall

[permalink] [raw]
Subject: Re: [Cocci] [PATCH] coccinelle: add patch rule for dma_alloc_coherent



On Fri, 21 Aug 2020, Alex Dewar wrote:

> Commit dfd32cad146e ("dma-mapping: remove dma_zalloc_coherent()")
> removed the definition of dma_zalloc_coherent() and also removed the
> corresponding patch rule for replacing instances of dma_alloc_coherent +
> memset in zalloc-simple.cocci (though left the report rule).
>
> Add a new patch rule to remove unnecessary calls to memset after
> allocating with dma_alloc_coherent. While we're at it, fix a couple of
> typos.

Applied, thanks!

julia

>
> Fixes: dfd32cad146e ("dma-mapping: remove dma_zalloc_coherent()")
> Signed-off-by: Alex Dewar <[email protected]>
> ---
> scripts/coccinelle/api/alloc/zalloc-simple.cocci | 16 +++++++++++++---
> 1 file changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/scripts/coccinelle/api/alloc/zalloc-simple.cocci b/scripts/coccinelle/api/alloc/zalloc-simple.cocci
> index 26cda3f48f01..b3d0c3c230c1 100644
> --- a/scripts/coccinelle/api/alloc/zalloc-simple.cocci
> +++ b/scripts/coccinelle/api/alloc/zalloc-simple.cocci
> @@ -127,6 +127,16 @@ statement S;
> if ((x==NULL) || ...) S
> - memset((T2)x,0,E1);
>
> +@depends on patch@
> +type T, T2;
> +expression x;
> +expression E1,E2,E3,E4;
> +statement S;
> +@@
> + x = (T)dma_alloc_coherent(E1, E2, E3, E4);
> + if ((x==NULL) || ...) S
> +- memset((T2)x, 0, E2);
> +
> //----------------------------------------------------------
> // For org mode
> //----------------------------------------------------------
> @@ -199,9 +209,9 @@ statement S;
> position p;
> @@
>
> - x = (T)dma_alloc_coherent@p(E2,E1,E3,E4);
> + x = (T)dma_alloc_coherent@p(E1,E2,E3,E4);
> if ((x==NULL) || ...) S
> - memset((T2)x,0,E1);
> + memset((T2)x,0,E2);
>
> @script:python depends on org@
> p << r2.p;
> @@ -217,7 +227,7 @@ p << r2.p;
> x << r2.x;
> @@
>
> -msg="WARNING: dma_alloc_coherent use in %s already zeroes out memory, so memset is not needed" % (x)
> +msg="WARNING: dma_alloc_coherent used in %s already zeroes out memory, so memset is not needed" % (x)
> coccilib.report.print_report(p[0], msg)
>
> //-----------------------------------------------------------------
> --
> 2.28.0
>
> _______________________________________________
> Cocci mailing list
> [email protected]
> https://systeme.lip6.fr/mailman/listinfo/cocci
>