Use device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at https://github.com/groeck/coccinelle-patches - Drop empty remove function - Use devm_add_action_or_reset() for calls to clk_disable_unprepare - Introduce local variable 'struct device *dev' and use it instead of dereferencing it repeatedly - Use devm_watchdog_register_driver() to register watchdog device Cc: Vladimir Zapolskiy <v...@mleia.com> Cc: Sylvain Lemieux <slemieux.t...@gmail.com> Signed-off-by: Guenter Roeck <li...@roeck-us.net> --- drivers/watchdog/pnx4008_wdt.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/drivers/watchdog/pnx4008_wdt.c b/drivers/watchdog/pnx4008_wdt.c index 24c266a9e1dc..f94d844e596c 100644 --- a/drivers/watchdog/pnx4008_wdt.c +++ b/drivers/watchdog/pnx4008_wdt.c @@ -183,52 +183,49 @@ static struct watchdog_device pnx4008_wdd = { .max_timeout = MAX_HEARTBEAT, }; +static void pnx4008_clk_disable_unprepare(void *data) +{ + clk_disable_unprepare(data); +} + static int pnx4008_wdt_probe(struct platform_device *pdev) { + struct device *dev = &pdev->dev; int ret = 0; - watchdog_init_timeout(&pnx4008_wdd, heartbeat, &pdev->dev); + watchdog_init_timeout(&pnx4008_wdd, heartbeat, dev); wdt_base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(wdt_base)) return PTR_ERR(wdt_base); - wdt_clk = devm_clk_get(&pdev->dev, NULL); + wdt_clk = devm_clk_get(dev, NULL); if (IS_ERR(wdt_clk)) return PTR_ERR(wdt_clk); ret = clk_prepare_enable(wdt_clk); if (ret) return ret; + ret = devm_add_action_or_reset(dev, pnx4008_clk_disable_unprepare, + wdt_clk); + if (ret) + return ret; pnx4008_wdd.bootstatus = (readl(WDTIM_RES(wdt_base)) & WDOG_RESET) ? WDIOF_CARDRESET : 0; - pnx4008_wdd.parent = &pdev->dev; + pnx4008_wdd.parent = dev; watchdog_set_nowayout(&pnx4008_wdd, nowayout); watchdog_set_restart_priority(&pnx4008_wdd, 128); pnx4008_wdt_stop(&pnx4008_wdd); /* disable for now */ - ret = watchdog_register_device(&pnx4008_wdd); + ret = devm_watchdog_register_device(dev, &pnx4008_wdd); if (ret < 0) { - dev_err(&pdev->dev, "cannot register watchdog device\n"); - goto disable_clk; + dev_err(dev, "cannot register watchdog device\n"); + return ret; } - dev_info(&pdev->dev, "heartbeat %d sec\n", pnx4008_wdd.timeout); - - return 0; - -disable_clk: - clk_disable_unprepare(wdt_clk); - return ret; -} - -static int pnx4008_wdt_remove(struct platform_device *pdev) -{ - watchdog_unregister_device(&pnx4008_wdd); - - clk_disable_unprepare(wdt_clk); + dev_info(dev, "heartbeat %d sec\n", pnx4008_wdd.timeout); return 0; } @@ -247,7 +244,6 @@ static struct platform_driver platform_wdt_driver = { .of_match_table = of_match_ptr(pnx4008_wdt_match), }, .probe = pnx4008_wdt_probe, - .remove = pnx4008_wdt_remove, }; module_platform_driver(platform_wdt_driver); -- 2.7.4