watchdog: armada_37xx_wdt: Convert to use device managed functions and other improvements

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 assignments to otherwise unused variables
- Drop unnecessary braces around conditional return statements
- Drop empty remove function
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
This commit is contained in:
Guenter Roeck 2019-04-08 12:38:25 -07:00 committed by Wim Van Sebroeck
parent b07e228eee
commit b09c153927
1 changed files with 14 additions and 29 deletions

View File

@ -244,6 +244,11 @@ static const struct watchdog_ops armada_37xx_wdt_ops = {
.get_timeleft = armada_37xx_wdt_get_timeleft,
};
static void armada_clk_disable_unprepare(void *data)
{
clk_disable_unprepare(data);
}
static int armada_37xx_wdt_probe(struct platform_device *pdev)
{
struct armada_37xx_watchdog *dev;
@ -278,12 +283,14 @@ static int armada_37xx_wdt_probe(struct platform_device *pdev)
ret = clk_prepare_enable(dev->clk);
if (ret)
return ret;
ret = devm_add_action_or_reset(&pdev->dev,
armada_clk_disable_unprepare, dev->clk);
if (ret)
return ret;
dev->clk_rate = clk_get_rate(dev->clk);
if (!dev->clk_rate) {
ret = -EINVAL;
goto disable_clk;
}
if (!dev->clk_rate)
return -EINVAL;
/*
* Since the timeout in seconds is given as 32 bit unsigned int, and
@ -307,35 +314,15 @@ static int armada_37xx_wdt_probe(struct platform_device *pdev)
set_bit(WDOG_HW_RUNNING, &dev->wdt.status);
watchdog_set_nowayout(&dev->wdt, nowayout);
ret = watchdog_register_device(&dev->wdt);
watchdog_stop_on_reboot(&dev->wdt);
ret = devm_watchdog_register_device(&pdev->dev, &dev->wdt);
if (ret)
goto disable_clk;
return ret;
dev_info(&pdev->dev, "Initial timeout %d sec%s\n",
dev->wdt.timeout, nowayout ? ", nowayout" : "");
return 0;
disable_clk:
clk_disable_unprepare(dev->clk);
return ret;
}
static int armada_37xx_wdt_remove(struct platform_device *pdev)
{
struct watchdog_device *wdt = platform_get_drvdata(pdev);
struct armada_37xx_watchdog *dev = watchdog_get_drvdata(wdt);
watchdog_unregister_device(wdt);
clk_disable_unprepare(dev->clk);
return 0;
}
static void armada_37xx_wdt_shutdown(struct platform_device *pdev)
{
struct watchdog_device *wdt = platform_get_drvdata(pdev);
armada_37xx_wdt_stop(wdt);
}
static int __maybe_unused armada_37xx_wdt_suspend(struct device *dev)
@ -370,8 +357,6 @@ MODULE_DEVICE_TABLE(of, armada_37xx_wdt_match);
static struct platform_driver armada_37xx_wdt_driver = {
.probe = armada_37xx_wdt_probe,
.remove = armada_37xx_wdt_remove,
.shutdown = armada_37xx_wdt_shutdown,
.driver = {
.name = "armada_37xx_wdt",
.of_match_table = of_match_ptr(armada_37xx_wdt_match),