Commit 553140a0 authored by Guenter Roeck's avatar Guenter Roeck Committed by Wim Van Sebroeck

watchdog: rtd119x_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
- Replace 'of_clk_get(np, 0)' with 'devm_clk_get(dev, NULL)'
- Introduce local variable 'struct device *dev' and use it instead of
  dereferencing it repeatedly
- Use devm_watchdog_register_driver() to register watchdog device
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarWim Van Sebroeck <wim@linux-watchdog.org>
parent cc718597
...@@ -95,12 +95,18 @@ static const struct of_device_id rtd119x_wdt_dt_ids[] = { ...@@ -95,12 +95,18 @@ static const struct of_device_id rtd119x_wdt_dt_ids[] = {
{ } { }
}; };
static void rtd119x_clk_disable_unprepare(void *data)
{
clk_disable_unprepare(data);
}
static int rtd119x_wdt_probe(struct platform_device *pdev) static int rtd119x_wdt_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev;
struct rtd119x_watchdog_device *data; struct rtd119x_watchdog_device *data;
int ret; int ret;
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;
...@@ -108,22 +114,24 @@ static int rtd119x_wdt_probe(struct platform_device *pdev) ...@@ -108,22 +114,24 @@ static int rtd119x_wdt_probe(struct platform_device *pdev)
if (IS_ERR(data->base)) if (IS_ERR(data->base))
return PTR_ERR(data->base); return PTR_ERR(data->base);
data->clk = of_clk_get(pdev->dev.of_node, 0); data->clk = devm_clk_get(dev, NULL);
if (IS_ERR(data->clk)) if (IS_ERR(data->clk))
return PTR_ERR(data->clk); return PTR_ERR(data->clk);
ret = clk_prepare_enable(data->clk); ret = clk_prepare_enable(data->clk);
if (ret) { if (ret)
clk_put(data->clk); return ret;
ret = devm_add_action_or_reset(dev, rtd119x_clk_disable_unprepare,
data->clk);
if (ret)
return ret; return ret;
}
data->wdt_dev.info = &rtd119x_wdt_info; data->wdt_dev.info = &rtd119x_wdt_info;
data->wdt_dev.ops = &rtd119x_wdt_ops; data->wdt_dev.ops = &rtd119x_wdt_ops;
data->wdt_dev.timeout = 120; data->wdt_dev.timeout = 120;
data->wdt_dev.max_timeout = 0xffffffff / clk_get_rate(data->clk); data->wdt_dev.max_timeout = 0xffffffff / clk_get_rate(data->clk);
data->wdt_dev.min_timeout = 1; data->wdt_dev.min_timeout = 1;
data->wdt_dev.parent = &pdev->dev; data->wdt_dev.parent = dev;
watchdog_stop_on_reboot(&data->wdt_dev); watchdog_stop_on_reboot(&data->wdt_dev);
watchdog_set_drvdata(&data->wdt_dev, data); watchdog_set_drvdata(&data->wdt_dev, data);
...@@ -133,31 +141,11 @@ static int rtd119x_wdt_probe(struct platform_device *pdev) ...@@ -133,31 +141,11 @@ static int rtd119x_wdt_probe(struct platform_device *pdev)
rtd119x_wdt_set_timeout(&data->wdt_dev, data->wdt_dev.timeout); rtd119x_wdt_set_timeout(&data->wdt_dev, data->wdt_dev.timeout);
rtd119x_wdt_stop(&data->wdt_dev); rtd119x_wdt_stop(&data->wdt_dev);
ret = watchdog_register_device(&data->wdt_dev); return devm_watchdog_register_device(dev, &data->wdt_dev);
if (ret) {
clk_disable_unprepare(data->clk);
clk_put(data->clk);
return ret;
}
return 0;
}
static int rtd119x_wdt_remove(struct platform_device *pdev)
{
struct rtd119x_watchdog_device *data = platform_get_drvdata(pdev);
watchdog_unregister_device(&data->wdt_dev);
clk_disable_unprepare(data->clk);
clk_put(data->clk);
return 0;
} }
static struct platform_driver rtd119x_wdt_driver = { static struct platform_driver rtd119x_wdt_driver = {
.probe = rtd119x_wdt_probe, .probe = rtd119x_wdt_probe,
.remove = rtd119x_wdt_remove,
.driver = { .driver = {
.name = "rtd1295-watchdog", .name = "rtd1295-watchdog",
.of_match_table = rtd119x_wdt_dt_ids, .of_match_table = rtd119x_wdt_dt_ids,
......
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