linux-kernel.vger.kernel.org archive mirror
 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 02/22] watchdog: asm9260_wdt: Convert to use device managed functions and other improvements
Date: Mon,  8 Apr 2019 12:38:26 -0700	[thread overview]
Message-ID: <1554752326-13319-3-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 empty remove function
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Introduce local variable 'struct device *dev' and use it instead of
  dereferencing it repeatedly
- 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/asm9260_wdt.c | 73 +++++++++++++++++-------------------------
 1 file changed, 29 insertions(+), 44 deletions(-)

diff --git a/drivers/watchdog/asm9260_wdt.c b/drivers/watchdog/asm9260_wdt.c
index 1de272bb2070..c5b9aae544dd 100644
--- a/drivers/watchdog/asm9260_wdt.c
+++ b/drivers/watchdog/asm9260_wdt.c
@@ -196,6 +196,11 @@ static const struct watchdog_ops asm9260_wdt_ops = {
 	.restart	= asm9260_restart,
 };
 
+static void asm9260_clk_disable_unprepare(void *data)
+{
+	clk_disable_unprepare(data);
+}
+
 static int asm9260_wdt_get_dt_clks(struct asm9260_wdt_priv *priv)
 {
 	int err;
@@ -219,26 +224,32 @@ static int asm9260_wdt_get_dt_clks(struct asm9260_wdt_priv *priv)
 		dev_err(priv->dev, "Failed to enable ahb_clk!\n");
 		return err;
 	}
+	err = devm_add_action_or_reset(priv->dev,
+				       asm9260_clk_disable_unprepare,
+				       priv->clk_ahb);
+	if (err)
+		return err;
 
 	err = clk_set_rate(priv->clk, CLOCK_FREQ);
 	if (err) {
-		clk_disable_unprepare(priv->clk_ahb);
 		dev_err(priv->dev, "Failed to set rate!\n");
 		return err;
 	}
 
 	err = clk_prepare_enable(priv->clk);
 	if (err) {
-		clk_disable_unprepare(priv->clk_ahb);
 		dev_err(priv->dev, "Failed to enable clk!\n");
 		return err;
 	}
+	err = devm_add_action_or_reset(priv->dev,
+				       asm9260_clk_disable_unprepare,
+				       priv->clk);
+	if (err)
+		return err;
 
 	/* wdt has internal divider */
 	clk = clk_get_rate(priv->clk);
 	if (!clk) {
-		clk_disable_unprepare(priv->clk);
-		clk_disable_unprepare(priv->clk_ahb);
 		dev_err(priv->dev, "Failed, clk is 0!\n");
 		return -EINVAL;
 	}
@@ -274,23 +285,23 @@ static void asm9260_wdt_get_dt_mode(struct asm9260_wdt_priv *priv)
 
 static int asm9260_wdt_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct asm9260_wdt_priv *priv;
 	struct watchdog_device *wdd;
 	int ret;
 	static const char * const mode_name[] = { "hw", "sw", "debug", };
 
-	priv = devm_kzalloc(&pdev->dev, sizeof(struct asm9260_wdt_priv),
-			    GFP_KERNEL);
+	priv = devm_kzalloc(dev, sizeof(struct asm9260_wdt_priv), GFP_KERNEL);
 	if (!priv)
 		return -ENOMEM;
 
-	priv->dev = &pdev->dev;
+	priv->dev = dev;
 
 	priv->iobase = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(priv->iobase))
 		return PTR_ERR(priv->iobase);
 
-	priv->rst = devm_reset_control_get_exclusive(&pdev->dev, "wdt_rst");
+	priv->rst = devm_reset_control_get_exclusive(dev, "wdt_rst");
 	if (IS_ERR(priv->rst))
 		return PTR_ERR(priv->rst);
 
@@ -303,7 +314,7 @@ static int asm9260_wdt_probe(struct platform_device *pdev)
 	wdd->ops = &asm9260_wdt_ops;
 	wdd->min_timeout = 1;
 	wdd->max_timeout = BM_WDTC_MAX(priv->wdt_freq);
-	wdd->parent = &pdev->dev;
+	wdd->parent = dev;
 
 	watchdog_set_drvdata(wdd, priv);
 
@@ -313,7 +324,7 @@ static int asm9260_wdt_probe(struct platform_device *pdev)
 	 * the max instead.
 	 */
 	wdd->timeout = ASM9260_WDT_DEFAULT_TIMEOUT;
-	watchdog_init_timeout(wdd, 0, &pdev->dev);
+	watchdog_init_timeout(wdd, 0, dev);
 
 	asm9260_wdt_get_dt_mode(priv);
 
@@ -325,49 +336,25 @@ static int asm9260_wdt_probe(struct platform_device *pdev)
 		 * Not all supported platforms specify an interrupt for the
 		 * watchdog, so let's make it optional.
 		 */
-		ret = devm_request_irq(&pdev->dev, priv->irq,
-				       asm9260_wdt_irq, 0, pdev->name, priv);
+		ret = devm_request_irq(dev, priv->irq, asm9260_wdt_irq, 0,
+				       pdev->name, priv);
 		if (ret < 0)
-			dev_warn(&pdev->dev, "failed to request IRQ\n");
+			dev_warn(dev, "failed to request IRQ\n");
 	}
 
 	watchdog_set_restart_priority(wdd, 128);
 
-	ret = watchdog_register_device(wdd);
+	watchdog_stop_on_reboot(wdd);
+	watchdog_stop_on_unregister(wdd);
+	ret = devm_watchdog_register_device(dev, wdd);
 	if (ret)
-		goto clk_off;
+		return ret;
 
 	platform_set_drvdata(pdev, priv);
 
-	dev_info(&pdev->dev, "Watchdog enabled (timeout: %d sec, mode: %s)\n",
+	dev_info(dev, "Watchdog enabled (timeout: %d sec, mode: %s)\n",
 		 wdd->timeout, mode_name[priv->mode]);
 	return 0;
-
-clk_off:
-	clk_disable_unprepare(priv->clk);
-	clk_disable_unprepare(priv->clk_ahb);
-	return ret;
-}
-
-static void asm9260_wdt_shutdown(struct platform_device *pdev)
-{
-	struct asm9260_wdt_priv *priv = platform_get_drvdata(pdev);
-
-	asm9260_wdt_disable(&priv->wdd);
-}
-
-static int asm9260_wdt_remove(struct platform_device *pdev)
-{
-	struct asm9260_wdt_priv *priv = platform_get_drvdata(pdev);
-
-	asm9260_wdt_disable(&priv->wdd);
-
-	watchdog_unregister_device(&priv->wdd);
-
-	clk_disable_unprepare(priv->clk);
-	clk_disable_unprepare(priv->clk_ahb);
-
-	return 0;
 }
 
 static const struct of_device_id asm9260_wdt_of_match[] = {
@@ -382,8 +369,6 @@ static struct platform_driver asm9260_wdt_driver = {
 		.of_match_table	= asm9260_wdt_of_match,
 	},
 	.probe = asm9260_wdt_probe,
-	.remove = asm9260_wdt_remove,
-	.shutdown = asm9260_wdt_shutdown,
 };
 module_platform_driver(asm9260_wdt_driver);
 
-- 
2.7.4


  parent 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 ` [PATCH 01/22] watchdog: armada_37xx_wdt: " Guenter Roeck
2019-04-08 19:38 ` Guenter Roeck [this message]
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-3-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).