Re: [Cocci] [PATCH v2] Coccinelle: api: Add SmPL script “use_devm_platform_get_and_ioremap_resource.cocci”
On Mon, 7 Sep 2020, Markus Elfring wrote: > >> +++ > >> b/scripts/coccinelle/api/use_devm_platform_get_and_ioremap_resource.cocci > >> @@ -0,0 +1,48 @@ > >> +// SPDX-License-Identifier: GPL-2.0 > >> +/// Simplify a function call combination by using a known wrapper > >> function. > >> +// > >> +// Keywords: wrapper function conversion ioremap resources > >> +// Confidence: High > > > > Shouldn't there be some options? --no-includes and perhaps > > --include-headers would seem reasonable. > > I imagine that the proposed source code transformation can work also without > additional semantic patch command options. It can. But it will be more efficient and more exhaustive if you include them. julia ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH v2] Coccinelle: api: Add SmPL script “use_devm_platform_get_and_ioremap_resource.cocci”
On Mon, 7 Sep 2020, Markus Elfring wrote: > From: Markus Elfring > Date: Mon, 7 Sep 2020 18:38:04 +0200 > > Another wrapper function is available since the commit > 890cc39a879906b63912482dfc41944579df2dc6 > ("drivers: provide devm_platform_get_and_ioremap_resource()"). > Provide safe design options for the adjustment of affected source code > by the means of the semantic patch language (Coccinelle software). > > Signed-off-by: Markus Elfring > --- > > v2: > Julia Lawall requested to omit case distinctions (disjunctions) from > the first SmPL script. > The usage of different expression metavariables for the first parameter > of function calls was too questionable for the proposed source > code transformation. > > > ...vm_platform_get_and_ioremap_resource.cocci | 48 +++ > 1 file changed, 48 insertions(+) > create mode 100644 > scripts/coccinelle/api/use_devm_platform_get_and_ioremap_resource.cocci > > diff --git > a/scripts/coccinelle/api/use_devm_platform_get_and_ioremap_resource.cocci > b/scripts/coccinelle/api/use_devm_platform_get_and_ioremap_resource.cocci > new file mode 100644 > index ..319583716ac8 > --- /dev/null > +++ b/scripts/coccinelle/api/use_devm_platform_get_and_ioremap_resource.cocci > @@ -0,0 +1,48 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/// Simplify a function call combination by using a known wrapper function. > +// > +// Keywords: wrapper function conversion ioremap resources > +// Confidence: High Shouldn't there be some options? --no-includes and perhaps --include-headers would seem reasonable. Please also remove all of the rule names except for "or" which is necessary. The rest just add clutter and make it harder to find the useful information, which is the depends on. Rules only need names if some other rule inherits their metavariables. julia > + > +virtual context, patch, report, org > + > +@display depends on context@ > +expression base, device, index, resource; > +@@ > +*resource = platform_get_resource(device, IORESOURCE_MEM, index); > + base = > +* devm_ioremap_resource > + (>dev, resource); > + > +@replacement depends on patch@ > +expression base, device, index, resource; > +@@ > +-resource = platform_get_resource(device, IORESOURCE_MEM, index); > + base = > +- devm_ioremap_resource > ++ devm_platform_get_and_ioremap_resource > + ( > +- & > + device > +-->dev > + , > +- resource > ++ index, > + ); > + > +@or depends on org || report@ > +expression base, device, index, resource; > +position p; > +@@ > + resource = platform_get_resource(device, IORESOURCE_MEM, index); > + base = devm_ioremap_resource@p(>dev, resource); > + > +@script:python to_do depends on org@ > +p << or.p; > +@@ > +coccilib.org.print_todo(p[0], "WARNING: opportunity for > devm_platform_get_and_ioremap_resource()") > + > +@script:python reporting depends on report@ > +p << or.p; > +@@ > +coccilib.report.print_report(p[0], "WARNING: opportunity for > devm_platform_get_and_ioremap_resource()") > -- > 2.28.0 > > ___ > Cocci mailing list > Cocci@systeme.lip6.fr > https://systeme.lip6.fr/mailman/listinfo/cocci > ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] [PATCH v2] Coccinelle: api: Add SmPL script “use_devm_platform_get_and_ioremap_resource.cocci”
From: Markus Elfring Date: Mon, 7 Sep 2020 18:38:04 +0200 Another wrapper function is available since the commit 890cc39a879906b63912482dfc41944579df2dc6 ("drivers: provide devm_platform_get_and_ioremap_resource()"). Provide safe design options for the adjustment of affected source code by the means of the semantic patch language (Coccinelle software). Signed-off-by: Markus Elfring --- v2: Julia Lawall requested to omit case distinctions (disjunctions) from the first SmPL script. The usage of different expression metavariables for the first parameter of function calls was too questionable for the proposed source code transformation. ...vm_platform_get_and_ioremap_resource.cocci | 48 +++ 1 file changed, 48 insertions(+) create mode 100644 scripts/coccinelle/api/use_devm_platform_get_and_ioremap_resource.cocci diff --git a/scripts/coccinelle/api/use_devm_platform_get_and_ioremap_resource.cocci b/scripts/coccinelle/api/use_devm_platform_get_and_ioremap_resource.cocci new file mode 100644 index ..319583716ac8 --- /dev/null +++ b/scripts/coccinelle/api/use_devm_platform_get_and_ioremap_resource.cocci @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-2.0 +/// Simplify a function call combination by using a known wrapper function. +// +// Keywords: wrapper function conversion ioremap resources +// Confidence: High + +virtual context, patch, report, org + +@display depends on context@ +expression base, device, index, resource; +@@ +*resource = platform_get_resource(device, IORESOURCE_MEM, index); + base = +* devm_ioremap_resource + (>dev, resource); + +@replacement depends on patch@ +expression base, device, index, resource; +@@ +-resource = platform_get_resource(device, IORESOURCE_MEM, index); + base = +- devm_ioremap_resource ++ devm_platform_get_and_ioremap_resource + ( +- & + device +-->dev + , +- resource ++ index, + ); + +@or depends on org || report@ +expression base, device, index, resource; +position p; +@@ + resource = platform_get_resource(device, IORESOURCE_MEM, index); + base = devm_ioremap_resource@p(>dev, resource); + +@script:python to_do depends on org@ +p << or.p; +@@ +coccilib.org.print_todo(p[0], "WARNING: opportunity for devm_platform_get_and_ioremap_resource()") + +@script:python reporting depends on report@ +p << or.p; +@@ +coccilib.report.print_report(p[0], "WARNING: opportunity for devm_platform_get_and_ioremap_resource()") -- 2.28.0 ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci