On Wed, 15 Apr 2020, Markus Elfring wrote:

> Hello,
>
> I noticed the suggestion “i2c: busses: convert to 
> devm_platform_get_and_ioremap_resource”.
> https://lore.kernel.org/linux-i2c/[email protected]/
> https://lore.kernel.org/patchwork/patch/1223734/
>
> I got into the mood to try another script out for the semantic patch language.
>
>
> @replacement@
> expression* base, device, resource;
> @@
> -resource = platform_get_resource(device, IORESOURCE_MEM, 0);
>  base =
> -       devm_ioremap_resource(&device->dev, resource)
> +       devm_platform_get_and_ioremap_resource(device, 0, &resource)
>  ;
>
>
> Source file example:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/i2c/busses/i2c-rcar.c?id=8632e9b5645bbc2331d21d892b0d6961c1a08429#n921
> https://elixir.bootlin.com/linux/v5.7-rc1/source/drivers/i2c/busses/i2c-rcar.c#L921
>
> // SPDX-License-Identifier: GPL-2.0
> // deleted part
> static int rcar_i2c_probe(struct platform_device *pdev)
> {
>       struct rcar_i2c_priv *priv;
>       struct i2c_adapter *adap;
>       struct device *dev = &pdev->dev;
> // deleted part
>       priv->res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>
>       priv->io = devm_ioremap_resource(dev, priv->res);
>       if (IS_ERR(priv->io))
>               return PTR_ERR(priv->io);
> // deleted part
> }
> // deleted part
>
>
> Now I wonder why the expected patch is not generated by the software
> “Coccinelle 1.0.8-00029-ga549b9f0” at the moment.
> How should this situation be improved?

Probably Coccinelle is not able to determine that priv->res and priv->io
are pointers, if you have not given it enough encouragement to look for
header files to find the defintion of the type of the priv structure.

I don't think that there is any need for the * in the metavariable
declaration.  If the various expressions are not pointers, the C compiler
would have complained.

julia


>
> Regards,
> Markus
> _______________________________________________
> Cocci mailing list
> [email protected]
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

Reply via email to