Commit 6ba3793c authored by Guenter Roeck's avatar Guenter Roeck Committed by Wim Van Sebroeck

watchdog: zx2967_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 empty remove function
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Use local variable 'struct device *dev' consistently
- Use devm_watchdog_register_driver() to register watchdog device

Cc: Jun Nie <jun.nie@linaro.org>
Cc: Shawn Guo <shawnguo@kernel.org>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
Acked-by: default avatarShawn Guo <shawnguo@kernel.org>
Signed-off-by: default avatarWim Van Sebroeck <wim@linux-watchdog.org>
parent f7daaa8d
...@@ -188,6 +188,11 @@ static void zx2967_wdt_reset_sysctrl(struct device *dev) ...@@ -188,6 +188,11 @@ static void zx2967_wdt_reset_sysctrl(struct device *dev)
of_node_put(out_args.np); of_node_put(out_args.np);
} }
static void zx2967_clk_disable_unprepare(void *data)
{
clk_disable_unprepare(data);
}
static int zx2967_wdt_probe(struct platform_device *pdev) static int zx2967_wdt_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
...@@ -206,7 +211,7 @@ static int zx2967_wdt_probe(struct platform_device *pdev) ...@@ -206,7 +211,7 @@ static int zx2967_wdt_probe(struct platform_device *pdev)
wdt->wdt_device.timeout = ZX2967_WDT_DEFAULT_TIMEOUT; wdt->wdt_device.timeout = ZX2967_WDT_DEFAULT_TIMEOUT;
wdt->wdt_device.max_timeout = ZX2967_WDT_MAX_TIMEOUT; wdt->wdt_device.max_timeout = ZX2967_WDT_MAX_TIMEOUT;
wdt->wdt_device.min_timeout = ZX2967_WDT_MIN_TIMEOUT; wdt->wdt_device.min_timeout = ZX2967_WDT_MIN_TIMEOUT;
wdt->wdt_device.parent = &pdev->dev; wdt->wdt_device.parent = dev;
wdt->reg_base = devm_platform_ioremap_resource(pdev, 0); wdt->reg_base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(wdt->reg_base)) if (IS_ERR(wdt->reg_base))
...@@ -225,13 +230,16 @@ static int zx2967_wdt_probe(struct platform_device *pdev) ...@@ -225,13 +230,16 @@ static int zx2967_wdt_probe(struct platform_device *pdev)
dev_err(dev, "failed to enable clock\n"); dev_err(dev, "failed to enable clock\n");
return ret; return ret;
} }
ret = devm_add_action_or_reset(dev, zx2967_clk_disable_unprepare,
wdt->clock);
if (ret)
return ret;
clk_set_rate(wdt->clock, ZX2967_WDT_CLK_FREQ); clk_set_rate(wdt->clock, ZX2967_WDT_CLK_FREQ);
rstc = devm_reset_control_get_exclusive(dev, NULL); rstc = devm_reset_control_get_exclusive(dev, NULL);
if (IS_ERR(rstc)) { if (IS_ERR(rstc)) {
dev_err(dev, "failed to get rstc"); dev_err(dev, "failed to get rstc");
ret = PTR_ERR(rstc); return PTR_ERR(rstc);
goto err;
} }
reset_control_assert(rstc); reset_control_assert(rstc);
...@@ -242,28 +250,14 @@ static int zx2967_wdt_probe(struct platform_device *pdev) ...@@ -242,28 +250,14 @@ static int zx2967_wdt_probe(struct platform_device *pdev)
ZX2967_WDT_DEFAULT_TIMEOUT, dev); ZX2967_WDT_DEFAULT_TIMEOUT, dev);
watchdog_set_nowayout(&wdt->wdt_device, WATCHDOG_NOWAYOUT); watchdog_set_nowayout(&wdt->wdt_device, WATCHDOG_NOWAYOUT);
ret = watchdog_register_device(&wdt->wdt_device); ret = devm_watchdog_register_device(dev, &wdt->wdt_device);
if (ret) if (ret)
goto err; return ret;
dev_info(dev, "watchdog enabled (timeout=%d sec, nowayout=%d)", dev_info(dev, "watchdog enabled (timeout=%d sec, nowayout=%d)",
wdt->wdt_device.timeout, WATCHDOG_NOWAYOUT); wdt->wdt_device.timeout, WATCHDOG_NOWAYOUT);
return 0; return 0;
err:
clk_disable_unprepare(wdt->clock);
return ret;
}
static int zx2967_wdt_remove(struct platform_device *pdev)
{
struct zx2967_wdt *wdt = platform_get_drvdata(pdev);
watchdog_unregister_device(&wdt->wdt_device);
clk_disable_unprepare(wdt->clock);
return 0;
} }
static const struct of_device_id zx2967_wdt_match[] = { static const struct of_device_id zx2967_wdt_match[] = {
...@@ -274,7 +268,6 @@ MODULE_DEVICE_TABLE(of, zx2967_wdt_match); ...@@ -274,7 +268,6 @@ MODULE_DEVICE_TABLE(of, zx2967_wdt_match);
static struct platform_driver zx2967_wdt_driver = { static struct platform_driver zx2967_wdt_driver = {
.probe = zx2967_wdt_probe, .probe = zx2967_wdt_probe,
.remove = zx2967_wdt_remove,
.driver = { .driver = {
.name = "zx2967-wdt", .name = "zx2967-wdt",
.of_match_table = of_match_ptr(zx2967_wdt_match), .of_match_table = of_match_ptr(zx2967_wdt_match),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment