Commit 80cb6bdd authored by Guenter Roeck's avatar Guenter Roeck Committed by Wim Van Sebroeck

watchdog: max63xx_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
- 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 d2a10c31
...@@ -200,11 +200,12 @@ static int max63xx_mmap_init(struct platform_device *p, struct max63xx_wdt *wdt) ...@@ -200,11 +200,12 @@ static int max63xx_mmap_init(struct platform_device *p, struct max63xx_wdt *wdt)
static int max63xx_wdt_probe(struct platform_device *pdev) static int max63xx_wdt_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev;
struct max63xx_wdt *wdt; struct max63xx_wdt *wdt;
struct max63xx_timeout *table; struct max63xx_timeout *table;
int err; int err;
wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL); wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
if (!wdt) if (!wdt)
return -ENOMEM; return -ENOMEM;
...@@ -215,7 +216,7 @@ static int max63xx_wdt_probe(struct platform_device *pdev) ...@@ -215,7 +216,7 @@ static int max63xx_wdt_probe(struct platform_device *pdev)
wdt->timeout = max63xx_select_timeout(table, heartbeat); wdt->timeout = max63xx_select_timeout(table, heartbeat);
if (!wdt->timeout) { if (!wdt->timeout) {
dev_err(&pdev->dev, "unable to satisfy %ds heartbeat request\n", dev_err(dev, "unable to satisfy %ds heartbeat request\n",
heartbeat); heartbeat);
return -EINVAL; return -EINVAL;
} }
...@@ -227,30 +228,22 @@ static int max63xx_wdt_probe(struct platform_device *pdev) ...@@ -227,30 +228,22 @@ static int max63xx_wdt_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, &wdt->wdd); platform_set_drvdata(pdev, &wdt->wdd);
watchdog_set_drvdata(&wdt->wdd, wdt); watchdog_set_drvdata(&wdt->wdd, wdt);
wdt->wdd.parent = &pdev->dev; wdt->wdd.parent = dev;
wdt->wdd.timeout = wdt->timeout->twd; wdt->wdd.timeout = wdt->timeout->twd;
wdt->wdd.info = &max63xx_wdt_info; wdt->wdd.info = &max63xx_wdt_info;
wdt->wdd.ops = &max63xx_wdt_ops; wdt->wdd.ops = &max63xx_wdt_ops;
watchdog_set_nowayout(&wdt->wdd, nowayout); watchdog_set_nowayout(&wdt->wdd, nowayout);
err = watchdog_register_device(&wdt->wdd); err = devm_watchdog_register_device(dev, &wdt->wdd);
if (err) if (err)
return err; return err;
dev_info(&pdev->dev, "using %ds heartbeat with %ds initial delay\n", dev_info(dev, "using %ds heartbeat with %ds initial delay\n",
wdt->timeout->twd, wdt->timeout->tdelay); wdt->timeout->twd, wdt->timeout->tdelay);
return 0; return 0;
} }
static int max63xx_wdt_remove(struct platform_device *pdev)
{
struct watchdog_device *wdd = platform_get_drvdata(pdev);
watchdog_unregister_device(wdd);
return 0;
}
static const struct platform_device_id max63xx_id_table[] = { static const struct platform_device_id max63xx_id_table[] = {
{ "max6369_wdt", (kernel_ulong_t)max6369_table, }, { "max6369_wdt", (kernel_ulong_t)max6369_table, },
{ "max6370_wdt", (kernel_ulong_t)max6369_table, }, { "max6370_wdt", (kernel_ulong_t)max6369_table, },
...@@ -264,7 +257,6 @@ MODULE_DEVICE_TABLE(platform, max63xx_id_table); ...@@ -264,7 +257,6 @@ MODULE_DEVICE_TABLE(platform, max63xx_id_table);
static struct platform_driver max63xx_wdt_driver = { static struct platform_driver max63xx_wdt_driver = {
.probe = max63xx_wdt_probe, .probe = max63xx_wdt_probe,
.remove = max63xx_wdt_remove,
.id_table = max63xx_id_table, .id_table = max63xx_id_table,
.driver = { .driver = {
.name = "max63xx_wdt", .name = "max63xx_wdt",
......
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