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>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@st.com>
Subject: [PATCH 13/22] watchdog: stm32_iwdg: Convert to use device managed functions and other improvements
Date: Wed, 10 Apr 2019 09:27:54 -0700	[thread overview]
Message-ID: <1554913683-25454-14-git-send-email-linux@roeck-us.net> (raw)
In-Reply-To: <1554913683-25454-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
- Introduce local variable 'struct device *dev' and use it instead of
  dereferencing it repeatedly
- Use devm_watchdog_register_driver() to register watchdog device

Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/stm32_iwdg.c | 65 +++++++++++++++++++++----------------------
 1 file changed, 31 insertions(+), 34 deletions(-)

diff --git a/drivers/watchdog/stm32_iwdg.c b/drivers/watchdog/stm32_iwdg.c
index 309563e002b8..68756a40eb36 100644
--- a/drivers/watchdog/stm32_iwdg.c
+++ b/drivers/watchdog/stm32_iwdg.c
@@ -138,38 +138,52 @@ static int stm32_iwdg_set_timeout(struct watchdog_device *wdd,
 	return 0;
 }
 
+static void stm32_clk_disable_unprepare(void *data)
+{
+	clk_disable_unprepare(data);
+}
+
 static int stm32_iwdg_clk_init(struct platform_device *pdev,
 			       struct stm32_iwdg *wdt)
 {
+	struct device *dev = &pdev->dev;
 	u32 ret;
 
-	wdt->clk_lsi = devm_clk_get(&pdev->dev, "lsi");
+	wdt->clk_lsi = devm_clk_get(dev, "lsi");
 	if (IS_ERR(wdt->clk_lsi)) {
-		dev_err(&pdev->dev, "Unable to get lsi clock\n");
+		dev_err(dev, "Unable to get lsi clock\n");
 		return PTR_ERR(wdt->clk_lsi);
 	}
 
 	/* optional peripheral clock */
 	if (wdt->has_pclk) {
-		wdt->clk_pclk = devm_clk_get(&pdev->dev, "pclk");
+		wdt->clk_pclk = devm_clk_get(dev, "pclk");
 		if (IS_ERR(wdt->clk_pclk)) {
-			dev_err(&pdev->dev, "Unable to get pclk clock\n");
+			dev_err(dev, "Unable to get pclk clock\n");
 			return PTR_ERR(wdt->clk_pclk);
 		}
 
 		ret = clk_prepare_enable(wdt->clk_pclk);
 		if (ret) {
-			dev_err(&pdev->dev, "Unable to prepare pclk clock\n");
+			dev_err(dev, "Unable to prepare pclk clock\n");
 			return ret;
 		}
+		ret = devm_add_action_or_reset(dev,
+					       stm32_clk_disable_unprepare,
+					       wdt->clk_pclk);
+		if (ret)
+			return ret;
 	}
 
 	ret = clk_prepare_enable(wdt->clk_lsi);
 	if (ret) {
-		dev_err(&pdev->dev, "Unable to prepare lsi clock\n");
-		clk_disable_unprepare(wdt->clk_pclk);
+		dev_err(dev, "Unable to prepare lsi clock\n");
 		return ret;
 	}
+	ret = devm_add_action_or_reset(dev, stm32_clk_disable_unprepare,
+				       wdt->clk_lsi);
+	if (ret)
+		return ret;
 
 	wdt->rate = clk_get_rate(wdt->clk_lsi);
 
@@ -199,16 +213,17 @@ MODULE_DEVICE_TABLE(of, stm32_iwdg_of_match);
 
 static int stm32_iwdg_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct watchdog_device *wdd;
 	const struct of_device_id *match;
 	struct stm32_iwdg *wdt;
 	int ret;
 
-	match = of_match_device(stm32_iwdg_of_match, &pdev->dev);
+	match = of_match_device(stm32_iwdg_of_match, dev);
 	if (!match)
 		return -ENODEV;
 
-	wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL);
+	wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
 	if (!wdt)
 		return -ENOMEM;
 
@@ -217,7 +232,7 @@ static int stm32_iwdg_probe(struct platform_device *pdev)
 	/* This is the timer base. */
 	wdt->regs = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(wdt->regs)) {
-		dev_err(&pdev->dev, "Could not get resource\n");
+		dev_err(dev, "Could not get resource\n");
 		return PTR_ERR(wdt->regs);
 	}
 
@@ -231,46 +246,28 @@ static int stm32_iwdg_probe(struct platform_device *pdev)
 	wdd->ops = &stm32_iwdg_ops;
 	wdd->min_timeout = ((RLR_MIN + 1) * 256) / wdt->rate;
 	wdd->max_hw_heartbeat_ms = ((RLR_MAX + 1) * 256 * 1000) / wdt->rate;
-	wdd->parent = &pdev->dev;
+	wdd->parent = dev;
 
 	watchdog_set_drvdata(wdd, wdt);
 	watchdog_set_nowayout(wdd, WATCHDOG_NOWAYOUT);
 
-	ret = watchdog_init_timeout(wdd, 0, &pdev->dev);
+	ret = watchdog_init_timeout(wdd, 0, dev);
 	if (ret)
-		dev_warn(&pdev->dev,
-			 "unable to set timeout value, using default\n");
+		dev_warn(dev, "unable to set timeout value, using default\n");
 
-	ret = watchdog_register_device(wdd);
+	ret = devm_watchdog_register_device(dev, wdd);
 	if (ret) {
-		dev_err(&pdev->dev, "failed to register watchdog device\n");
-		goto err;
+		dev_err(dev, "failed to register watchdog device\n");
+		return ret;
 	}
 
 	platform_set_drvdata(pdev, wdt);
 
 	return 0;
-err:
-	clk_disable_unprepare(wdt->clk_lsi);
-	clk_disable_unprepare(wdt->clk_pclk);
-
-	return ret;
-}
-
-static int stm32_iwdg_remove(struct platform_device *pdev)
-{
-	struct stm32_iwdg *wdt = platform_get_drvdata(pdev);
-
-	watchdog_unregister_device(&wdt->wdd);
-	clk_disable_unprepare(wdt->clk_lsi);
-	clk_disable_unprepare(wdt->clk_pclk);
-
-	return 0;
 }
 
 static struct platform_driver stm32_iwdg_driver = {
 	.probe		= stm32_iwdg_probe,
-	.remove		= stm32_iwdg_remove,
 	.driver = {
 		.name	= "iwdg",
 		.of_match_table = of_match_ptr(stm32_iwdg_of_match),
-- 
2.7.4


  parent reply	other threads:[~2019-04-10 16:28 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-10 16:27 [PATCH 00/22] watchdog: Expand use of device managed functions (series 3 of 3) Guenter Roeck
2019-04-10 16:27 ` [PATCH 01/22] watchdog: tegra_wdt: Use watchdog_stop_on_unregister and other improvements Guenter Roeck
2019-04-10 16:27 ` [PATCH 02/22] watchdog: tqmx86_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
2019-04-10 16:27 ` [PATCH 03/22] watchdog: ts4800_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-10 16:27 ` [PATCH 04/22] watchdog: ts72xx_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
2019-04-10 16:27 ` [PATCH 05/22] watchdog: twl4030_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-10 16:27 ` [PATCH 06/22] watchdog: uniphier_wdt: drop platform_set_drvdata Guenter Roeck
2019-04-10 16:27 ` [PATCH 07/22] watchdog: wdat_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
2019-04-10 16:27 ` [PATCH 08/22] watchdog: wm831x_wdt: " Guenter Roeck
2019-04-10 16:27 ` [PATCH 09/22] watchdog: xen_wdt: " Guenter Roeck
2019-04-10 16:27 ` [PATCH 10/22] watchdog: imx_sc_wdt: " Guenter Roeck
2019-04-11  8:48   ` Shawn Guo
2019-04-10 16:27 ` [PATCH 11/22] watchdog: sbsa_gwdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-10 16:27 ` [PATCH 12/22] watchdog: zx2967_wdt: " Guenter Roeck
2019-04-11  8:53   ` Shawn Guo
2019-04-10 16:27 ` Guenter Roeck [this message]
2019-04-10 16:27 ` [PATCH 14/22] watchdog: ux500_wdt: " Guenter Roeck
2019-04-10 16:27 ` [PATCH 15/22] watchdog: pic32-dmt: " Guenter Roeck
2019-04-10 16:27 ` [PATCH 16/22] watchdog: pic32-wdt: " Guenter Roeck
2019-04-10 16:27 ` [PATCH 17/22] watchdog: loongson1_wdt: " Guenter Roeck
2019-04-10 16:27 ` [PATCH 18/22] watchdog: mt7621_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
2019-04-10 18:46   ` Joe Perches
2019-04-10 19:54     ` Guenter Roeck
2019-04-10 22:10       ` Joe Perches
2019-04-10 22:15         ` Guenter Roeck
2019-04-10 16:28 ` [PATCH 19/22] watchdog: rt2880_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-10 16:28 ` [PATCH 20/22] watchdog: jz4740_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
2019-04-10 16:52   ` Joe Perches
2019-04-10 17:47     ` Guenter Roeck
2019-04-10 16:28 ` [PATCH 21/22] watchdog: mpc8xxx_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-23 13:28   ` Christophe Leroy
2019-04-10 16:28 ` [PATCH 22/22] watchdog: pnx4008_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=1554913683-25454-14-git-send-email-linux@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=alexandre.torgue@st.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=mcoquelin.stm32@gmail.com \
    --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).