All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Wim Van Sebroeck <wim@linux-watchdog.org>
Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org,
	Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH 01/22] watchdog: armada_37xx_wdt: Convert to use device managed functions and other improvements
Date: Mon,  8 Apr 2019 12:38:25 -0700	[thread overview]
Message-ID: <1554752326-13319-2-git-send-email-linux@roeck-us.net> (raw)
In-Reply-To: <1554752326-13319-1-git-send-email-linux@roeck-us.net>

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
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

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

diff --git a/drivers/watchdog/armada_37xx_wdt.c b/drivers/watchdog/armada_37xx_wdt.c
index 4b4054f54df9..e5dcb26d85f0 100644
--- a/drivers/watchdog/armada_37xx_wdt.c
+++ b/drivers/watchdog/armada_37xx_wdt.c
@@ -244,6 +244,11 @@ static const struct watchdog_ops armada_37xx_wdt_ops = {
 	.get_timeleft = armada_37xx_wdt_get_timeleft,
 };
 
+static void armada_clk_disable_unprepare(void *data)
+{
+	clk_disable_unprepare(data);
+}
+
 static int armada_37xx_wdt_probe(struct platform_device *pdev)
 {
 	struct armada_37xx_watchdog *dev;
@@ -278,12 +283,14 @@ static int armada_37xx_wdt_probe(struct platform_device *pdev)
 	ret = clk_prepare_enable(dev->clk);
 	if (ret)
 		return ret;
+	ret = devm_add_action_or_reset(&pdev->dev,
+				       armada_clk_disable_unprepare, dev->clk);
+	if (ret)
+		return ret;
 
 	dev->clk_rate = clk_get_rate(dev->clk);
-	if (!dev->clk_rate) {
-		ret = -EINVAL;
-		goto disable_clk;
-	}
+	if (!dev->clk_rate)
+		return -EINVAL;
 
 	/*
 	 * Since the timeout in seconds is given as 32 bit unsigned int, and
@@ -307,35 +314,15 @@ static int armada_37xx_wdt_probe(struct platform_device *pdev)
 		set_bit(WDOG_HW_RUNNING, &dev->wdt.status);
 
 	watchdog_set_nowayout(&dev->wdt, nowayout);
-	ret = watchdog_register_device(&dev->wdt);
+	watchdog_stop_on_reboot(&dev->wdt);
+	ret = devm_watchdog_register_device(&pdev->dev, &dev->wdt);
 	if (ret)
-		goto disable_clk;
+		return ret;
 
 	dev_info(&pdev->dev, "Initial timeout %d sec%s\n",
 		 dev->wdt.timeout, nowayout ? ", nowayout" : "");
 
 	return 0;
-
-disable_clk:
-	clk_disable_unprepare(dev->clk);
-	return ret;
-}
-
-static int armada_37xx_wdt_remove(struct platform_device *pdev)
-{
-	struct watchdog_device *wdt = platform_get_drvdata(pdev);
-	struct armada_37xx_watchdog *dev = watchdog_get_drvdata(wdt);
-
-	watchdog_unregister_device(wdt);
-	clk_disable_unprepare(dev->clk);
-	return 0;
-}
-
-static void armada_37xx_wdt_shutdown(struct platform_device *pdev)
-{
-	struct watchdog_device *wdt = platform_get_drvdata(pdev);
-
-	armada_37xx_wdt_stop(wdt);
 }
 
 static int __maybe_unused armada_37xx_wdt_suspend(struct device *dev)
@@ -370,8 +357,6 @@ MODULE_DEVICE_TABLE(of, armada_37xx_wdt_match);
 
 static struct platform_driver armada_37xx_wdt_driver = {
 	.probe		= armada_37xx_wdt_probe,
-	.remove		= armada_37xx_wdt_remove,
-	.shutdown	= armada_37xx_wdt_shutdown,
 	.driver		= {
 		.name	= "armada_37xx_wdt",
 		.of_match_table = of_match_ptr(armada_37xx_wdt_match),
-- 
2.7.4


  reply	other threads:[~2019-04-08 19:41 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-08 19:38 [PATCH 00/22] watchdog: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-08 19:38 ` Guenter Roeck [this message]
2019-04-08 19:38 ` [PATCH 02/22] watchdog: asm9260_wdt: " Guenter Roeck
2019-04-08 19:38 ` [PATCH 03/22] watchdog: aspeed_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
2019-04-09  0:37   ` Andrew Jeffery
2019-04-09  1:03     ` Guenter Roeck
2019-04-09  1:05       ` Andrew Jeffery
2019-04-08 19:38 ` [PATCH 04/22] watchdog: atlas7_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-08 19:38 ` [PATCH 05/22] watchdog: bcm2835_wdt: drop platform_set_drvdata Guenter Roeck
2019-04-09  6:54   ` Stefan Wahren
2019-04-08 19:38 ` [PATCH 06/22] watchdog: bcm7038_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-08 19:38 ` [PATCH 07/22] watchdog: bcm_kona_wdt: " Guenter Roeck
2019-04-09 16:36   ` Ray Jui
2019-04-08 19:38 ` [PATCH 08/22] watchdog: cadence_wdt: " Guenter Roeck
2019-04-08 19:38 ` [PATCH 09/22] watchdog: da9052_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
2019-04-10 12:12   ` Steve Twiss
2019-04-08 19:38 ` [PATCH 10/22] watchdog: da9055_wdt: " Guenter Roeck
2019-04-10 12:14   ` Steve Twiss
2019-04-08 19:38 ` [PATCH 11/22] watchdog: da9062_wdt: " Guenter Roeck
2019-04-10 12:20   ` Steve Twiss
2019-04-08 19:38 ` [PATCH 12/22] watchdog: da9063_wdt: " Guenter Roeck
2019-04-10 12:50   ` Steve Twiss
2019-04-10 13:11     ` Guenter Roeck
2019-04-08 19:38 ` [PATCH 13/22] watchdog: davinci_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-08 19:38 ` [PATCH 14/22] watchdog: ep93xx_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
2019-04-08 19:38 ` [PATCH 15/22] watchdog: ftwdt010_wdt: Use 'dev' consistently Guenter Roeck
2019-04-08 19:38 ` [PATCH 16/22] watchdog: gpio_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-08 19:38 ` [PATCH 17/22] watchdog: iTCO_wdt: Various improvements Guenter Roeck
2019-04-08 19:38 ` [PATCH 18/22] watchdog: imgpdc_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-08 19:38 ` [PATCH 19/22] watchdog: intel-mid_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
2019-04-08 19:38 ` [PATCH 20/22] watchdog: kempld_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-08 19:38 ` [PATCH 21/22] watchdog: lpc18xx_wdt: " Guenter Roeck
2019-04-08 19:38 ` [PATCH 22/22] watchdog: max63xx_wdt: " Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1554752326-13319-2-git-send-email-linux@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=wim@linux-watchdog.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.