watchdog: bcm7038_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
- 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:30 -07:00 committed by Wim Van Sebroeck
parent dcbb613fa8
commit 69656dcd4f
1 changed files with 13 additions and 25 deletions

View File

@ -107,6 +107,11 @@ static const struct watchdog_ops bcm7038_wdt_ops = {
.get_timeleft = bcm7038_wdt_get_timeleft, .get_timeleft = bcm7038_wdt_get_timeleft,
}; };
static void bcm7038_clk_disable_unprepare(void *data)
{
clk_disable_unprepare(data);
}
static int bcm7038_wdt_probe(struct platform_device *pdev) static int bcm7038_wdt_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
@ -127,6 +132,11 @@ static int bcm7038_wdt_probe(struct platform_device *pdev)
/* If unable to get clock, use default frequency */ /* If unable to get clock, use default frequency */
if (!IS_ERR(wdt->clk)) { if (!IS_ERR(wdt->clk)) {
err = clk_prepare_enable(wdt->clk); err = clk_prepare_enable(wdt->clk);
if (err)
return err;
err = devm_add_action_or_reset(dev,
bcm7038_clk_disable_unprepare,
wdt->clk);
if (err) if (err)
return err; return err;
wdt->rate = clk_get_rate(wdt->clk); wdt->rate = clk_get_rate(wdt->clk);
@ -146,10 +156,11 @@ static int bcm7038_wdt_probe(struct platform_device *pdev)
wdt->wdd.parent = dev; wdt->wdd.parent = dev;
watchdog_set_drvdata(&wdt->wdd, wdt); watchdog_set_drvdata(&wdt->wdd, wdt);
err = watchdog_register_device(&wdt->wdd); watchdog_stop_on_reboot(&wdt->wdd);
watchdog_stop_on_unregister(&wdt->wdd);
err = devm_watchdog_register_device(dev, &wdt->wdd);
if (err) { if (err) {
dev_err(dev, "Failed to register watchdog device\n"); dev_err(dev, "Failed to register watchdog device\n");
clk_disable_unprepare(wdt->clk);
return err; return err;
} }
@ -158,19 +169,6 @@ static int bcm7038_wdt_probe(struct platform_device *pdev)
return 0; return 0;
} }
static int bcm7038_wdt_remove(struct platform_device *pdev)
{
struct bcm7038_watchdog *wdt = platform_get_drvdata(pdev);
if (!nowayout)
bcm7038_wdt_stop(&wdt->wdd);
watchdog_unregister_device(&wdt->wdd);
clk_disable_unprepare(wdt->clk);
return 0;
}
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
static int bcm7038_wdt_suspend(struct device *dev) static int bcm7038_wdt_suspend(struct device *dev)
{ {
@ -196,14 +194,6 @@ static int bcm7038_wdt_resume(struct device *dev)
static SIMPLE_DEV_PM_OPS(bcm7038_wdt_pm_ops, bcm7038_wdt_suspend, static SIMPLE_DEV_PM_OPS(bcm7038_wdt_pm_ops, bcm7038_wdt_suspend,
bcm7038_wdt_resume); bcm7038_wdt_resume);
static void bcm7038_wdt_shutdown(struct platform_device *pdev)
{
struct bcm7038_watchdog *wdt = platform_get_drvdata(pdev);
if (watchdog_active(&wdt->wdd))
bcm7038_wdt_stop(&wdt->wdd);
}
static const struct of_device_id bcm7038_wdt_match[] = { static const struct of_device_id bcm7038_wdt_match[] = {
{ .compatible = "brcm,bcm7038-wdt" }, { .compatible = "brcm,bcm7038-wdt" },
{}, {},
@ -212,8 +202,6 @@ MODULE_DEVICE_TABLE(of, bcm7038_wdt_match);
static struct platform_driver bcm7038_wdt_driver = { static struct platform_driver bcm7038_wdt_driver = {
.probe = bcm7038_wdt_probe, .probe = bcm7038_wdt_probe,
.remove = bcm7038_wdt_remove,
.shutdown = bcm7038_wdt_shutdown,
.driver = { .driver = {
.name = "bcm7038-wdt", .name = "bcm7038-wdt",
.of_match_table = bcm7038_wdt_match, .of_match_table = bcm7038_wdt_match,