watchdog: ts4800_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: 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-10 09:27:44 -07:00 committed by Wim Van Sebroeck
parent 09fb6d010a
commit 44affc086e
1 changed files with 11 additions and 22 deletions

View File

@ -108,7 +108,8 @@ static const struct watchdog_info ts4800_wdt_info = {
static int ts4800_wdt_probe(struct platform_device *pdev) static int ts4800_wdt_probe(struct platform_device *pdev)
{ {
struct device_node *np = pdev->dev.of_node; struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
struct device_node *syscon_np; struct device_node *syscon_np;
struct watchdog_device *wdd; struct watchdog_device *wdd;
struct ts4800_wdt *wdt; struct ts4800_wdt *wdt;
@ -117,18 +118,18 @@ static int ts4800_wdt_probe(struct platform_device *pdev)
syscon_np = of_parse_phandle(np, "syscon", 0); syscon_np = of_parse_phandle(np, "syscon", 0);
if (!syscon_np) { if (!syscon_np) {
dev_err(&pdev->dev, "no syscon property\n"); dev_err(dev, "no syscon property\n");
return -ENODEV; return -ENODEV;
} }
ret = of_property_read_u32_index(np, "syscon", 1, &reg); ret = of_property_read_u32_index(np, "syscon", 1, &reg);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "no offset in syscon\n"); dev_err(dev, "no offset in syscon\n");
return ret; return ret;
} }
/* allocate memory for watchdog struct */ /* allocate memory for watchdog struct */
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;
@ -137,13 +138,13 @@ static int ts4800_wdt_probe(struct platform_device *pdev)
wdt->regmap = syscon_node_to_regmap(syscon_np); wdt->regmap = syscon_node_to_regmap(syscon_np);
of_node_put(syscon_np); of_node_put(syscon_np);
if (IS_ERR(wdt->regmap)) { if (IS_ERR(wdt->regmap)) {
dev_err(&pdev->dev, "cannot get parent's regmap\n"); dev_err(dev, "cannot get parent's regmap\n");
return PTR_ERR(wdt->regmap); return PTR_ERR(wdt->regmap);
} }
/* Initialize struct watchdog_device */ /* Initialize struct watchdog_device */
wdd = &wdt->wdd; wdd = &wdt->wdd;
wdd->parent = &pdev->dev; wdd->parent = dev;
wdd->info = &ts4800_wdt_info; wdd->info = &ts4800_wdt_info;
wdd->ops = &ts4800_wdt_ops; wdd->ops = &ts4800_wdt_ops;
wdd->min_timeout = ts4800_wdt_map[0].timeout; wdd->min_timeout = ts4800_wdt_map[0].timeout;
@ -151,7 +152,7 @@ static int ts4800_wdt_probe(struct platform_device *pdev)
watchdog_set_drvdata(wdd, wdt); watchdog_set_drvdata(wdd, wdt);
watchdog_set_nowayout(wdd, nowayout); watchdog_set_nowayout(wdd, nowayout);
watchdog_init_timeout(wdd, 0, &pdev->dev); watchdog_init_timeout(wdd, 0, dev);
/* /*
* As this watchdog supports only a few values, ts4800_wdt_set_timeout * As this watchdog supports only a few values, ts4800_wdt_set_timeout
@ -169,31 +170,20 @@ static int ts4800_wdt_probe(struct platform_device *pdev)
*/ */
ts4800_wdt_stop(wdd); ts4800_wdt_stop(wdd);
ret = watchdog_register_device(wdd); ret = devm_watchdog_register_device(dev, wdd);
if (ret) { if (ret) {
dev_err(&pdev->dev, dev_err(dev, "failed to register watchdog device\n");
"failed to register watchdog device\n");
return ret; return ret;
} }
platform_set_drvdata(pdev, wdt); platform_set_drvdata(pdev, wdt);
dev_info(&pdev->dev, dev_info(dev, "initialized (timeout = %d sec, nowayout = %d)\n",
"initialized (timeout = %d sec, nowayout = %d)\n",
wdd->timeout, nowayout); wdd->timeout, nowayout);
return 0; return 0;
} }
static int ts4800_wdt_remove(struct platform_device *pdev)
{
struct ts4800_wdt *wdt = platform_get_drvdata(pdev);
watchdog_unregister_device(&wdt->wdd);
return 0;
}
static const struct of_device_id ts4800_wdt_of_match[] = { static const struct of_device_id ts4800_wdt_of_match[] = {
{ .compatible = "technologic,ts4800-wdt", }, { .compatible = "technologic,ts4800-wdt", },
{ }, { },
@ -202,7 +192,6 @@ MODULE_DEVICE_TABLE(of, ts4800_wdt_of_match);
static struct platform_driver ts4800_wdt_driver = { static struct platform_driver ts4800_wdt_driver = {
.probe = ts4800_wdt_probe, .probe = ts4800_wdt_probe,
.remove = ts4800_wdt_remove,
.driver = { .driver = {
.name = "ts4800_wdt", .name = "ts4800_wdt",
.of_match_table = ts4800_wdt_of_match, .of_match_table = ts4800_wdt_of_match,