diff mbox series

[21/22] watchdog: mpc8xxx_wdt: Convert to use device managed functions and other improvements

Message ID 1554913683-25454-22-git-send-email-linux@roeck-us.net (mailing list archive)
State Accepted
Headers show
Series watchdog: Expand use of device managed functions (series 3 of 3) | expand

Commit Message

Guenter Roeck April 10, 2019, 4:28 p.m. UTC
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
  This also drops the inaccurate message on remove; the driver won't be
  removed if the hardware watchdog is running, no matter if the watchdog
  device is open or not.
- Use local variable 'struct device *dev' consistently
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/mpc8xxx_wdt.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)

Comments

Christophe Leroy April 23, 2019, 1:28 p.m. UTC | #1
Le 10/04/2019 à 18:28, Guenter Roeck a écrit :
> 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
>    This also drops the inaccurate message on remove; the driver won't be
>    removed if the hardware watchdog is running, no matter if the watchdog
>    device is open or not.
> - Use local variable 'struct device *dev' consistently
> - Use devm_watchdog_register_driver() to register watchdog device
> 
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

Reviewed-by: Christophe Leroy <christophe.leroy@c-s.fr>

> ---
>   drivers/watchdog/mpc8xxx_wdt.c | 17 +++--------------
>   1 file changed, 3 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/watchdog/mpc8xxx_wdt.c b/drivers/watchdog/mpc8xxx_wdt.c
> index 3b5b446b690c..9b6d6a5a27ad 100644
> --- a/drivers/watchdog/mpc8xxx_wdt.c
> +++ b/drivers/watchdog/mpc8xxx_wdt.c
> @@ -204,9 +204,10 @@ static int mpc8xxx_wdt_probe(struct platform_device *ofdev)
>   	if (ddata->wdd.timeout < ddata->wdd.min_timeout)
>   		ddata->wdd.timeout = ddata->wdd.min_timeout;
>   
> -	ret = watchdog_register_device(&ddata->wdd);
> +	ret = devm_watchdog_register_device(dev, &ddata->wdd);
>   	if (ret) {
> -		dev_err(dev, "cannot register watchdog device (err=%d)\n", ret);
> +		dev_err(dev, "cannot register watchdog device (err=%d)\n",
> +			ret);
>   		return ret;
>   	}
>   
> @@ -218,17 +219,6 @@ static int mpc8xxx_wdt_probe(struct platform_device *ofdev)
>   	return 0;
>   }
>   
> -static int mpc8xxx_wdt_remove(struct platform_device *ofdev)
> -{
> -	struct mpc8xxx_wdt_ddata *ddata = platform_get_drvdata(ofdev);
> -
> -	dev_crit(&ofdev->dev, "Watchdog removed, expect the %s soon!\n",
> -		 reset ? "reset" : "machine check exception");
> -	watchdog_unregister_device(&ddata->wdd);
> -
> -	return 0;
> -}
> -
>   static const struct of_device_id mpc8xxx_wdt_match[] = {
>   	{
>   		.compatible = "mpc83xx_wdt",
> @@ -259,7 +249,6 @@ MODULE_DEVICE_TABLE(of, mpc8xxx_wdt_match);
>   
>   static struct platform_driver mpc8xxx_wdt_driver = {
>   	.probe		= mpc8xxx_wdt_probe,
> -	.remove		= mpc8xxx_wdt_remove,
>   	.driver = {
>   		.name = "mpc8xxx_wdt",
>   		.of_match_table = mpc8xxx_wdt_match,
>
diff mbox series

Patch

diff --git a/drivers/watchdog/mpc8xxx_wdt.c b/drivers/watchdog/mpc8xxx_wdt.c
index 3b5b446b690c..9b6d6a5a27ad 100644
--- a/drivers/watchdog/mpc8xxx_wdt.c
+++ b/drivers/watchdog/mpc8xxx_wdt.c
@@ -204,9 +204,10 @@  static int mpc8xxx_wdt_probe(struct platform_device *ofdev)
 	if (ddata->wdd.timeout < ddata->wdd.min_timeout)
 		ddata->wdd.timeout = ddata->wdd.min_timeout;
 
-	ret = watchdog_register_device(&ddata->wdd);
+	ret = devm_watchdog_register_device(dev, &ddata->wdd);
 	if (ret) {
-		dev_err(dev, "cannot register watchdog device (err=%d)\n", ret);
+		dev_err(dev, "cannot register watchdog device (err=%d)\n",
+			ret);
 		return ret;
 	}
 
@@ -218,17 +219,6 @@  static int mpc8xxx_wdt_probe(struct platform_device *ofdev)
 	return 0;
 }
 
-static int mpc8xxx_wdt_remove(struct platform_device *ofdev)
-{
-	struct mpc8xxx_wdt_ddata *ddata = platform_get_drvdata(ofdev);
-
-	dev_crit(&ofdev->dev, "Watchdog removed, expect the %s soon!\n",
-		 reset ? "reset" : "machine check exception");
-	watchdog_unregister_device(&ddata->wdd);
-
-	return 0;
-}
-
 static const struct of_device_id mpc8xxx_wdt_match[] = {
 	{
 		.compatible = "mpc83xx_wdt",
@@ -259,7 +249,6 @@  MODULE_DEVICE_TABLE(of, mpc8xxx_wdt_match);
 
 static struct platform_driver mpc8xxx_wdt_driver = {
 	.probe		= mpc8xxx_wdt_probe,
-	.remove		= mpc8xxx_wdt_remove,
 	.driver = {
 		.name = "mpc8xxx_wdt",
 		.of_match_table = mpc8xxx_wdt_match,