Re: [PATCH] watchdog: Convert to use devm_platform_ioremap_resource

From: Vladimir Zapolskiy
Date: Fri Apr 05 2019 - 13:59:58 EST


On 04/02/2019 10:01 PM, Guenter Roeck wrote:
> Use devm_platform_ioremap_resource to reduce source code size,
> improve readability, and reduce the likelyhood of bugs.
>
> The conversion was done automatically with coccinelle using the
> following semantic patch.
>
> @r@
> identifier res, pdev;
> expression a;
> expression index;
> expression e;
> @@
>
> <+...
> - res = platform_get_resource(pdev, IORESOURCE_MEM, index);
> - a = devm_ioremap_resource(e, res);
> + a = devm_platform_ioremap_resource(pdev, index);
> ...+>
>
> @depends on r@
> identifier r.res;
> @@
> - struct resource *res;
> ... when != res
>
> @@
> identifier res, pdev;
> expression index;
> expression a;
> @@
> - struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, index);
> - a = devm_ioremap_resource(&pdev->dev, res);
> + a = devm_platform_ioremap_resource(pdev, index);
>
> Cc: Joel Stanley <joel@xxxxxxxxx>
> Cc: Nicolas Ferre <nicolas.ferre@xxxxxxxxxxxxx>
> Cc: Alexandre Belloni <alexandre.belloni@xxxxxxxxxxx>
> Cc: Florian Fainelli <f.fainelli@xxxxxxxxx>
> Cc: Linus Walleij <linus.walleij@xxxxxxxxxx>
> Cc: Baruch Siach <baruch@xxxxxxxxxx>
> Cc: Keguang Zhang <keguang.zhang@xxxxxxxxx>
> Cc: Vladimir Zapolskiy <vz@xxxxxxxxx>
> Cc: Kevin Hilman <khilman@xxxxxxxxxxxx>
> Cc: Matthias Brugger <matthias.bgg@xxxxxxxxx>
> Cc: Avi Fishman <avifishman70@xxxxxxxxx>
> Cc: Nancy Yuen <yuenn@xxxxxxxxxx>
> Cc: Brendan Higgins <brendanhiggins@xxxxxxxxxx>
> Cc: Wan ZongShun <mcuos.com@xxxxxxxxx>
> Cc: Michal Simek <michal.simek@xxxxxxxxxx>
> Cc: Sylvain Lemieux <slemieux.tyco@xxxxxxxxx>
> Cc: Kukjin Kim <kgene@xxxxxxxxxx>
> Cc: Barry Song <baohua@xxxxxxxxxx>
> Cc: Orson Zhai <orsonzhai@xxxxxxxxx>
> Cc: Patrice Chotard <patrice.chotard@xxxxxx>
> Cc: Maxime Coquelin <mcoquelin.stm32@xxxxxxxxx>
> Cc: Maxime Ripard <maxime.ripard@xxxxxxxxxxx>
> Cc: Chen-Yu Tsai <wens@xxxxxxxx>
> Cc: Marc Gonzalez <marc.w.gonzalez@xxxxxxx>
> Cc: Thierry Reding <thierry.reding@xxxxxxxxx>
> Cc: Shawn Guo <shawnguo@xxxxxxxxxx>
> Signed-off-by: Guenter Roeck <linux@xxxxxxxxxxxx>
> ---
> drivers/watchdog/asm9260_wdt.c | 4 +---
> drivers/watchdog/aspeed_wdt.c | 4 +---
> drivers/watchdog/at91sam9_wdt.c | 4 +---
> drivers/watchdog/ath79_wdt.c | 4 +---
> drivers/watchdog/atlas7_wdt.c | 4 +---
> drivers/watchdog/bcm7038_wdt.c | 4 +---
> drivers/watchdog/bcm_kona_wdt.c | 4 +---
> drivers/watchdog/cadence_wdt.c | 4 +---
> drivers/watchdog/coh901327_wdt.c | 4 +---
> drivers/watchdog/davinci_wdt.c | 4 +---
> drivers/watchdog/digicolor_wdt.c | 4 +---
> drivers/watchdog/dw_wdt.c | 4 +---
> drivers/watchdog/ep93xx_wdt.c | 4 +---
> drivers/watchdog/ftwdt010_wdt.c | 4 +---
> drivers/watchdog/imgpdc_wdt.c | 4 +---
> drivers/watchdog/jz4740_wdt.c | 4 +---
> drivers/watchdog/lantiq_wdt.c | 4 +---
> drivers/watchdog/loongson1_wdt.c | 4 +---
> drivers/watchdog/lpc18xx_wdt.c | 4 +---
> drivers/watchdog/max63xx_wdt.c | 4 +---
> drivers/watchdog/meson_gxbb_wdt.c | 4 +---
> drivers/watchdog/meson_wdt.c | 4 +---
> drivers/watchdog/moxart_wdt.c | 4 +---
> drivers/watchdog/mpc8xxx_wdt.c | 3 +--
> drivers/watchdog/mt7621_wdt.c | 5 +----
> drivers/watchdog/mtk_wdt.c | 4 +---
> drivers/watchdog/npcm_wdt.c | 4 +---
> drivers/watchdog/nuc900_wdt.c | 4 +---
> drivers/watchdog/of_xilinx_wdt.c | 4 +---
> drivers/watchdog/omap_wdt.c | 4 +---
> drivers/watchdog/orion_wdt.c | 6 ++----
> drivers/watchdog/pic32-dmt.c | 4 +---
> drivers/watchdog/pic32-wdt.c | 4 +---
> drivers/watchdog/pnx4008_wdt.c | 4 +---
> drivers/watchdog/renesas_wdt.c | 4 +---
> drivers/watchdog/rt2880_wdt.c | 4 +---
> drivers/watchdog/rtd119x_wdt.c | 4 +---
> drivers/watchdog/rza_wdt.c | 4 +---
> drivers/watchdog/s3c2410_wdt.c | 4 +---
> drivers/watchdog/sama5d4_wdt.c | 4 +---
> drivers/watchdog/sbsa_gwdt.c | 7 ++-----
> drivers/watchdog/shwdt.c | 4 +---
> drivers/watchdog/sirfsoc_wdt.c | 4 +---
> drivers/watchdog/sprd_wdt.c | 4 +---
> drivers/watchdog/st_lpc_wdt.c | 4 +---
> drivers/watchdog/stm32_iwdg.c | 4 +---
> drivers/watchdog/sunxi_wdt.c | 4 +---
> drivers/watchdog/tangox_wdt.c | 4 +---
> drivers/watchdog/tegra_wdt.c | 4 +---
> drivers/watchdog/ts72xx_wdt.c | 7 ++-----
> drivers/watchdog/txx9wdt.c | 4 +---
> drivers/watchdog/zx2967_wdt.c | 4 +---
> 52 files changed, 55 insertions(+), 161 deletions(-)

[snip]

> diff --git a/drivers/watchdog/lpc18xx_wdt.c b/drivers/watchdog/lpc18xx_wdt.c
> index 331cadb459ac..f6f66634cedf 100644
> --- a/drivers/watchdog/lpc18xx_wdt.c
> +++ b/drivers/watchdog/lpc18xx_wdt.c
> @@ -204,15 +204,13 @@ static int lpc18xx_wdt_probe(struct platform_device *pdev)
> {
> struct lpc18xx_wdt_dev *lpc18xx_wdt;
> struct device *dev = &pdev->dev;
> - struct resource *res;
> int ret;
>
> lpc18xx_wdt = devm_kzalloc(dev, sizeof(*lpc18xx_wdt), GFP_KERNEL);
> if (!lpc18xx_wdt)
> return -ENOMEM;
>
> - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> - lpc18xx_wdt->base = devm_ioremap_resource(dev, res);
> + lpc18xx_wdt->base = devm_platform_ioremap_resource(pdev, 0);
> if (IS_ERR(lpc18xx_wdt->base))
> return PTR_ERR(lpc18xx_wdt->base);
>

[snip]

> diff --git a/drivers/watchdog/pnx4008_wdt.c b/drivers/watchdog/pnx4008_wdt.c
> index 8e261799c84e..24c266a9e1dc 100644
> --- a/drivers/watchdog/pnx4008_wdt.c
> +++ b/drivers/watchdog/pnx4008_wdt.c
> @@ -185,13 +185,11 @@ static struct watchdog_device pnx4008_wdd = {
>
> static int pnx4008_wdt_probe(struct platform_device *pdev)
> {
> - struct resource *r;
> int ret = 0;
>
> watchdog_init_timeout(&pnx4008_wdd, heartbeat, &pdev->dev);
>
> - r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> - wdt_base = devm_ioremap_resource(&pdev->dev, r);
> + wdt_base = devm_platform_ioremap_resource(pdev, 0);
> if (IS_ERR(wdt_base))
> return PTR_ERR(wdt_base);
>

For lpc18xx_wdt.c and pnx4008_wdt.c:

Acked-by: Vladimir Zapolskiy <vz@xxxxxxxxx>

--
Best wishes,
Vladimir