linux-watchdog.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>,
	Andy Gross <andy.gross@linaro.org>,
	David Brown <david.brown@linaro.org>
Subject: [PATCH 12/23] watchdog: qcom-wdt: Convert to use device managed functions and other improvements
Date: Tue,  9 Apr 2019 10:23:50 -0700	[thread overview]
Message-ID: <1554830641-9247-13-git-send-email-linux@roeck-us.net> (raw)
In-Reply-To: <1554830641-9247-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: Andy Gross <andy.gross@linaro.org>
Cc: David Brown <david.brown@linaro.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/qcom-wdt.c | 55 +++++++++++++++++++++------------------------
 1 file changed, 25 insertions(+), 30 deletions(-)

diff --git a/drivers/watchdog/qcom-wdt.c b/drivers/watchdog/qcom-wdt.c
index 5dfd604477a4..6d29c33b1316 100644
--- a/drivers/watchdog/qcom-wdt.c
+++ b/drivers/watchdog/qcom-wdt.c
@@ -142,22 +142,28 @@ static const struct watchdog_info qcom_wdt_info = {
 	.identity	= KBUILD_MODNAME,
 };
 
+static void qcom_clk_disable_unprepare(void *data)
+{
+	clk_disable_unprepare(data);
+}
+
 static int qcom_wdt_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct qcom_wdt *wdt;
 	struct resource *res;
-	struct device_node *np = pdev->dev.of_node;
+	struct device_node *np = dev->of_node;
 	const u32 *regs;
 	u32 percpu_offset;
 	int ret;
 
-	regs = of_device_get_match_data(&pdev->dev);
+	regs = of_device_get_match_data(dev);
 	if (!regs) {
-		dev_err(&pdev->dev, "Unsupported QCOM WDT module\n");
+		dev_err(dev, "Unsupported QCOM WDT module\n");
 		return -ENODEV;
 	}
 
-	wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL);
+	wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
 	if (!wdt)
 		return -ENOMEM;
 
@@ -172,21 +178,25 @@ static int qcom_wdt_probe(struct platform_device *pdev)
 	res->start += percpu_offset;
 	res->end += percpu_offset;
 
-	wdt->base = devm_ioremap_resource(&pdev->dev, res);
+	wdt->base = devm_ioremap_resource(dev, res);
 	if (IS_ERR(wdt->base))
 		return PTR_ERR(wdt->base);
 
-	wdt->clk = devm_clk_get(&pdev->dev, NULL);
+	wdt->clk = devm_clk_get(dev, NULL);
 	if (IS_ERR(wdt->clk)) {
-		dev_err(&pdev->dev, "failed to get input clock\n");
+		dev_err(dev, "failed to get input clock\n");
 		return PTR_ERR(wdt->clk);
 	}
 
 	ret = clk_prepare_enable(wdt->clk);
 	if (ret) {
-		dev_err(&pdev->dev, "failed to setup clock\n");
+		dev_err(dev, "failed to setup clock\n");
 		return ret;
 	}
+	ret = devm_add_action_or_reset(dev, qcom_clk_disable_unprepare,
+				       wdt->clk);
+	if (ret)
+		return ret;
 
 	/*
 	 * We use the clock rate to calculate the max timeout, so ensure it's
@@ -199,16 +209,15 @@ static int qcom_wdt_probe(struct platform_device *pdev)
 	wdt->rate = clk_get_rate(wdt->clk);
 	if (wdt->rate == 0 ||
 	    wdt->rate > 0x10000000U) {
-		dev_err(&pdev->dev, "invalid clock rate\n");
-		ret = -EINVAL;
-		goto err_clk_unprepare;
+		dev_err(dev, "invalid clock rate\n");
+		return -EINVAL;
 	}
 
 	wdt->wdd.info = &qcom_wdt_info;
 	wdt->wdd.ops = &qcom_wdt_ops;
 	wdt->wdd.min_timeout = 1;
 	wdt->wdd.max_timeout = 0x10000000U / wdt->rate;
-	wdt->wdd.parent = &pdev->dev;
+	wdt->wdd.parent = dev;
 	wdt->layout = regs;
 
 	if (readl(wdt_addr(wdt, WDT_STS)) & 1)
@@ -220,29 +229,16 @@ static int qcom_wdt_probe(struct platform_device *pdev)
 	 * the max instead.
 	 */
 	wdt->wdd.timeout = min(wdt->wdd.max_timeout, 30U);
-	watchdog_init_timeout(&wdt->wdd, 0, &pdev->dev);
+	watchdog_init_timeout(&wdt->wdd, 0, dev);
 
-	ret = watchdog_register_device(&wdt->wdd);
+	ret = devm_watchdog_register_device(dev, &wdt->wdd);
 	if (ret) {
-		dev_err(&pdev->dev, "failed to register watchdog\n");
-		goto err_clk_unprepare;
+		dev_err(dev, "failed to register watchdog\n");
+		return ret;
 	}
 
 	platform_set_drvdata(pdev, wdt);
 	return 0;
-
-err_clk_unprepare:
-	clk_disable_unprepare(wdt->clk);
-	return ret;
-}
-
-static int qcom_wdt_remove(struct platform_device *pdev)
-{
-	struct qcom_wdt *wdt = platform_get_drvdata(pdev);
-
-	watchdog_unregister_device(&wdt->wdd);
-	clk_disable_unprepare(wdt->clk);
-	return 0;
 }
 
 static int __maybe_unused qcom_wdt_suspend(struct device *dev)
@@ -277,7 +273,6 @@ MODULE_DEVICE_TABLE(of, qcom_wdt_of_table);
 
 static struct platform_driver qcom_watchdog_driver = {
 	.probe	= qcom_wdt_probe,
-	.remove	= qcom_wdt_remove,
 	.driver	= {
 		.name		= KBUILD_MODNAME,
 		.of_match_table	= qcom_wdt_of_table,
-- 
2.7.4


  parent reply	other threads:[~2019-04-09 17:25 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
2019-04-09 17:23 ` [PATCH 01/23] watchdog: max77620_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-09 17:23 ` [PATCH 02/23] watchdog: mena21_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
2019-04-11  7:18   ` Johannes Thumshirn
2019-04-09 17:23 ` [PATCH 03/23] watchdog: menf21bmc_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-09 17:23 ` [PATCH 04/23] watchdog: meson_gxbb_wdt: " Guenter Roeck
2019-04-09 17:23 ` [PATCH 05/23] watchdog: meson_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
2019-04-09 17:23 ` [PATCH 06/23] watchdog: mlx_wdt: " Guenter Roeck
2019-04-09 17:23 ` [PATCH 07/23] watchdog: moxart_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-09 17:23 ` [PATCH 08/23] watchdog: mtk_wdt: " Guenter Roeck
2019-04-09 17:23 ` [PATCH 09/23] watchdog: npcm_wdt: Use local variable 'dev' consistently Guenter Roeck
2019-04-09 17:23 ` [PATCH 10/23] watchdog: of_xilinx_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-10  6:38   ` Michal Simek
2019-04-10 12:09     ` Guenter Roeck
2019-04-09 17:23 ` [PATCH 11/23] watchdog: pm8916_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
2019-04-09 17:23 ` Guenter Roeck [this message]
2019-04-09 17:23 ` [PATCH 13/23] watchdog: rn5t618_wdt: " Guenter Roeck
2019-04-09 17:23 ` [PATCH 14/23] watchdog: rtd119x_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-09 17:23 ` [PATCH 15/23] watchdog: rza_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
2019-04-09 17:23 ` [PATCH 16/23] watchdog: sama5d4_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-09 17:23 ` [PATCH 17/23] watchdog: sirfsoc_wdt: " Guenter Roeck
2019-04-09 17:23 ` [PATCH 18/23] watchdog: 1: " Guenter Roeck
2019-04-09 17:38   ` Guenter Roeck
2019-04-09 17:23 ` [PATCH 19/23] watchdog: st_lpc_wdt: Convert to use device managed functions Guenter Roeck
2019-04-10  7:26   ` Patrice CHOTARD
2019-04-09 17:23 ` [PATCH 20/23] watchdog: stmp3xxx_rtc_wdt: " Guenter Roeck
2019-04-09 17:23 ` [PATCH 21/23] watchdog: stpmic1_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
2019-04-09 17:24 ` [PATCH 22/23] watchdog: sunxi_wdt: " Guenter Roeck
2019-04-10  7:06   ` Maxime Ripard
2019-04-09 17:24 ` [PATCH 23/23] watchdog: tangox_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-10 11:20   ` Måns Rullgård

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=1554830641-9247-13-git-send-email-linux@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=andy.gross@linaro.org \
    --cc=david.brown@linaro.org \
    --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).