diff mbox series

[23/23] watchdog: tangox_wdt: Convert to use device managed functions and other improvements

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

Commit Message

Guenter Roeck April 9, 2019, 5:24 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 unnecessary braces around conditional return statements
- Drop empty remove function
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace stop on remove with call to watchdog_stop_on_unregister()
- Use devm_watchdog_register_driver() to register watchdog device

Cc: Marc Gonzalez <marc.w.gonzalez@free.fr>
Cc: Mans Rullgard <mans@mansr.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/tangox_wdt.c | 37 ++++++++++++++-----------------------
 1 file changed, 14 insertions(+), 23 deletions(-)

Comments

Måns Rullgård April 10, 2019, 11:20 a.m. UTC | #1
Guenter Roeck <linux@roeck-us.net> writes:

> 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 unnecessary braces around conditional return statements
> - Drop empty remove function
> - Use devm_add_action_or_reset() for calls to clk_disable_unprepare
> - Replace stop on remove with call to watchdog_stop_on_unregister()
> - Use devm_watchdog_register_driver() to register watchdog device
>
> Cc: Marc Gonzalez <marc.w.gonzalez@free.fr>
> Cc: Mans Rullgard <mans@mansr.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
>  drivers/watchdog/tangox_wdt.c | 37 ++++++++++++++-----------------------
>  1 file changed, 14 insertions(+), 23 deletions(-)

Acked-by: Mans Rullgard <mans@mansr.com>

> diff --git a/drivers/watchdog/tangox_wdt.c b/drivers/watchdog/tangox_wdt.c
> index 16611fe0d9d1..1afb0e9d808c 100644
> --- a/drivers/watchdog/tangox_wdt.c
> +++ b/drivers/watchdog/tangox_wdt.c
> @@ -108,6 +108,11 @@ static const struct watchdog_ops tangox_wdt_ops = {
>  	.restart	= tangox_wdt_restart,
>  };
>
> +static void tangox_clk_disable_unprepare(void *data)
> +{
> +	clk_disable_unprepare(data);
> +}
> +
>  static int tangox_wdt_probe(struct platform_device *pdev)
>  {
>  	struct tangox_wdt_device *dev;
> @@ -129,12 +134,14 @@ static int tangox_wdt_probe(struct platform_device *pdev)
>  	err = clk_prepare_enable(dev->clk);
>  	if (err)
>  		return err;
> +	err = devm_add_action_or_reset(&pdev->dev,
> +				       tangox_clk_disable_unprepare, dev->clk);
> +	if (err)
> +		return err;
>
>  	dev->clk_rate = clk_get_rate(dev->clk);
> -	if (!dev->clk_rate) {
> -		err = -EINVAL;
> -		goto err;
> -	}
> +	if (!dev->clk_rate)
> +		return -EINVAL;
>
>  	dev->wdt.parent = &pdev->dev;
>  	dev->wdt.info = &tangox_wdt_info;
> @@ -168,31 +175,16 @@ static int tangox_wdt_probe(struct platform_device *pdev)
>
>  	watchdog_set_restart_priority(&dev->wdt, 128);
>
> -	err = watchdog_register_device(&dev->wdt);
> +	watchdog_stop_on_unregister(&dev->wdt);
> +	err = devm_watchdog_register_device(&pdev->dev, &dev->wdt);
>  	if (err)
> -		goto err;
> +		return err;
>
>  	platform_set_drvdata(pdev, dev);
>
>  	dev_info(&pdev->dev, "SMP86xx/SMP87xx watchdog registered\n");
>
>  	return 0;
> -
> - err:
> -	clk_disable_unprepare(dev->clk);
> -	return err;
> -}
> -
> -static int tangox_wdt_remove(struct platform_device *pdev)
> -{
> -	struct tangox_wdt_device *dev = platform_get_drvdata(pdev);
> -
> -	tangox_wdt_stop(&dev->wdt);
> -	clk_disable_unprepare(dev->clk);
> -
> -	watchdog_unregister_device(&dev->wdt);
> -
> -	return 0;
>  }
>
>  static const struct of_device_id tangox_wdt_dt_ids[] = {
> @@ -204,7 +196,6 @@ MODULE_DEVICE_TABLE(of, tangox_wdt_dt_ids);
>
>  static struct platform_driver tangox_wdt_driver = {
>  	.probe	= tangox_wdt_probe,
> -	.remove	= tangox_wdt_remove,
>  	.driver	= {
>  		.name		= "tangox-wdt",
>  		.of_match_table	= tangox_wdt_dt_ids,
> -- 
> 2.7.4
>
diff mbox series

Patch

diff --git a/drivers/watchdog/tangox_wdt.c b/drivers/watchdog/tangox_wdt.c
index 16611fe0d9d1..1afb0e9d808c 100644
--- a/drivers/watchdog/tangox_wdt.c
+++ b/drivers/watchdog/tangox_wdt.c
@@ -108,6 +108,11 @@  static const struct watchdog_ops tangox_wdt_ops = {
 	.restart	= tangox_wdt_restart,
 };
 
+static void tangox_clk_disable_unprepare(void *data)
+{
+	clk_disable_unprepare(data);
+}
+
 static int tangox_wdt_probe(struct platform_device *pdev)
 {
 	struct tangox_wdt_device *dev;
@@ -129,12 +134,14 @@  static int tangox_wdt_probe(struct platform_device *pdev)
 	err = clk_prepare_enable(dev->clk);
 	if (err)
 		return err;
+	err = devm_add_action_or_reset(&pdev->dev,
+				       tangox_clk_disable_unprepare, dev->clk);
+	if (err)
+		return err;
 
 	dev->clk_rate = clk_get_rate(dev->clk);
-	if (!dev->clk_rate) {
-		err = -EINVAL;
-		goto err;
-	}
+	if (!dev->clk_rate)
+		return -EINVAL;
 
 	dev->wdt.parent = &pdev->dev;
 	dev->wdt.info = &tangox_wdt_info;
@@ -168,31 +175,16 @@  static int tangox_wdt_probe(struct platform_device *pdev)
 
 	watchdog_set_restart_priority(&dev->wdt, 128);
 
-	err = watchdog_register_device(&dev->wdt);
+	watchdog_stop_on_unregister(&dev->wdt);
+	err = devm_watchdog_register_device(&pdev->dev, &dev->wdt);
 	if (err)
-		goto err;
+		return err;
 
 	platform_set_drvdata(pdev, dev);
 
 	dev_info(&pdev->dev, "SMP86xx/SMP87xx watchdog registered\n");
 
 	return 0;
-
- err:
-	clk_disable_unprepare(dev->clk);
-	return err;
-}
-
-static int tangox_wdt_remove(struct platform_device *pdev)
-{
-	struct tangox_wdt_device *dev = platform_get_drvdata(pdev);
-
-	tangox_wdt_stop(&dev->wdt);
-	clk_disable_unprepare(dev->clk);
-
-	watchdog_unregister_device(&dev->wdt);
-
-	return 0;
 }
 
 static const struct of_device_id tangox_wdt_dt_ids[] = {
@@ -204,7 +196,6 @@  MODULE_DEVICE_TABLE(of, tangox_wdt_dt_ids);
 
 static struct platform_driver tangox_wdt_driver = {
 	.probe	= tangox_wdt_probe,
-	.remove	= tangox_wdt_remove,
 	.driver	= {
 		.name		= "tangox-wdt",
 		.of_match_table	= tangox_wdt_dt_ids,