Commit 0c4ece9b authored by Guenter Roeck's avatar Guenter Roeck Committed by Wim Van Sebroeck

watchdog: menf21bmc_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

Cc: Andreas Werner <andreas.werner@men.de>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarWim Van Sebroeck <wim@linux-watchdog.org>
parent 94ac20d8
...@@ -117,12 +117,12 @@ static const struct watchdog_ops menf21bmc_wdt_ops = { ...@@ -117,12 +117,12 @@ static const struct watchdog_ops menf21bmc_wdt_ops = {
static int menf21bmc_wdt_probe(struct platform_device *pdev) static int menf21bmc_wdt_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev;
int ret, bmc_timeout; int ret, bmc_timeout;
struct menf21bmc_wdt *drv_data; struct menf21bmc_wdt *drv_data;
struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent); struct i2c_client *i2c_client = to_i2c_client(dev->parent);
drv_data = devm_kzalloc(&pdev->dev, drv_data = devm_kzalloc(dev, sizeof(struct menf21bmc_wdt), GFP_KERNEL);
sizeof(struct menf21bmc_wdt), GFP_KERNEL);
if (!drv_data) if (!drv_data)
return -ENOMEM; return -ENOMEM;
...@@ -130,7 +130,7 @@ static int menf21bmc_wdt_probe(struct platform_device *pdev) ...@@ -130,7 +130,7 @@ static int menf21bmc_wdt_probe(struct platform_device *pdev)
drv_data->wdt.info = &menf21bmc_wdt_info; drv_data->wdt.info = &menf21bmc_wdt_info;
drv_data->wdt.min_timeout = BMC_WD_TIMEOUT_MIN; drv_data->wdt.min_timeout = BMC_WD_TIMEOUT_MIN;
drv_data->wdt.max_timeout = BMC_WD_TIMEOUT_MAX; drv_data->wdt.max_timeout = BMC_WD_TIMEOUT_MAX;
drv_data->wdt.parent = &pdev->dev; drv_data->wdt.parent = dev;
drv_data->i2c_client = i2c_client; drv_data->i2c_client = i2c_client;
/* /*
...@@ -140,40 +140,28 @@ static int menf21bmc_wdt_probe(struct platform_device *pdev) ...@@ -140,40 +140,28 @@ static int menf21bmc_wdt_probe(struct platform_device *pdev)
bmc_timeout = i2c_smbus_read_word_data(drv_data->i2c_client, bmc_timeout = i2c_smbus_read_word_data(drv_data->i2c_client,
BMC_CMD_WD_TIME); BMC_CMD_WD_TIME);
if (bmc_timeout < 0) { if (bmc_timeout < 0) {
dev_err(&pdev->dev, "failed to get current WDT timeout\n"); dev_err(dev, "failed to get current WDT timeout\n");
return bmc_timeout; return bmc_timeout;
} }
watchdog_init_timeout(&drv_data->wdt, bmc_timeout / 10, &pdev->dev); watchdog_init_timeout(&drv_data->wdt, bmc_timeout / 10, dev);
watchdog_set_nowayout(&drv_data->wdt, nowayout); watchdog_set_nowayout(&drv_data->wdt, nowayout);
watchdog_set_drvdata(&drv_data->wdt, drv_data); watchdog_set_drvdata(&drv_data->wdt, drv_data);
platform_set_drvdata(pdev, drv_data); platform_set_drvdata(pdev, drv_data);
ret = menf21bmc_wdt_set_bootstatus(drv_data); ret = menf21bmc_wdt_set_bootstatus(drv_data);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "failed to set Watchdog bootstatus\n"); dev_err(dev, "failed to set Watchdog bootstatus\n");
return ret; return ret;
} }
ret = watchdog_register_device(&drv_data->wdt); ret = devm_watchdog_register_device(dev, &drv_data->wdt);
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to register Watchdog device\n"); dev_err(dev, "failed to register Watchdog device\n");
return ret; return ret;
} }
dev_info(&pdev->dev, "MEN 14F021P00 BMC Watchdog device enabled\n"); dev_info(dev, "MEN 14F021P00 BMC Watchdog device enabled\n");
return 0;
}
static int menf21bmc_wdt_remove(struct platform_device *pdev)
{
struct menf21bmc_wdt *drv_data = platform_get_drvdata(pdev);
dev_warn(&pdev->dev,
"Unregister MEN 14F021P00 BMC Watchdog device, board may reset\n");
watchdog_unregister_device(&drv_data->wdt);
return 0; return 0;
} }
...@@ -191,7 +179,6 @@ static struct platform_driver menf21bmc_wdt = { ...@@ -191,7 +179,6 @@ static struct platform_driver menf21bmc_wdt = {
.name = DEVNAME, .name = DEVNAME,
}, },
.probe = menf21bmc_wdt_probe, .probe = menf21bmc_wdt_probe,
.remove = menf21bmc_wdt_remove,
.shutdown = menf21bmc_wdt_shutdown, .shutdown = menf21bmc_wdt_shutdown,
}; };
......
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