From: Rosen Penev <rosenp@gmail.com>
To: linux-watchdog@vger.kernel.org
Cc: Wim Van Sebroeck <wim@linux-watchdog.org>,
Guenter Roeck <linux@roeck-us.net>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] watchdog: orion_wdt: Use devm APIs for clock and watchdog management
Date: Tue, 19 May 2026 14:42:29 -0700 [thread overview]
Message-ID: <20260519214229.16656-1-rosenp@gmail.com> (raw)
Replace clk_get/clk_prepare_enable/clk_put with devm_clk_get_enabled
and devm_clk_get_optional_enabled so the clock lifecycle is managed
automatically. Switch to devm_watchdog_register_device to eliminate
the manual remove callback and the disable_clk error path.
Switching to devm in these functions is fine as the proper
platform_device is passed in.
Assisted-by: Claude:Sonnet-4.6
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/watchdog/orion_wdt.c | 64 +++++++-----------------------------
1 file changed, 12 insertions(+), 52 deletions(-)
diff --git a/drivers/watchdog/orion_wdt.c b/drivers/watchdog/orion_wdt.c
index a92701ff2653..85e9877de952 100644
--- a/drivers/watchdog/orion_wdt.c
+++ b/drivers/watchdog/orion_wdt.c
@@ -80,14 +80,9 @@ static int orion_wdt_clock_init(struct platform_device *pdev,
{
int ret;
- dev->clk = clk_get(&pdev->dev, NULL);
+ dev->clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(dev->clk))
return PTR_ERR(dev->clk);
- ret = clk_prepare_enable(dev->clk);
- if (ret) {
- clk_put(dev->clk);
- return ret;
- }
dev->clk_rate = clk_get_rate(dev->clk);
return 0;
@@ -98,14 +93,9 @@ static int armada370_wdt_clock_init(struct platform_device *pdev,
{
int ret;
- dev->clk = clk_get(&pdev->dev, NULL);
+ dev->clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(dev->clk))
return PTR_ERR(dev->clk);
- ret = clk_prepare_enable(dev->clk);
- if (ret) {
- clk_put(dev->clk);
- return ret;
- }
/* Setup watchdog input clock */
atomic_io_modify(dev->reg + TIMER_CTRL,
@@ -121,14 +111,11 @@ static int armada375_wdt_clock_init(struct platform_device *pdev,
{
int ret;
- dev->clk = of_clk_get_by_name(pdev->dev.of_node, "fixed");
- if (!IS_ERR(dev->clk)) {
- ret = clk_prepare_enable(dev->clk);
- if (ret) {
- clk_put(dev->clk);
- return ret;
- }
+ dev->clk = devm_clk_get_optional_enabled(&pdev->dev, "fixed");
+ if (IS_ERR(dev->clk))
+ return PTR_ERR(dev->clk);
+ if (dev->clk) {
atomic_io_modify(dev->reg + TIMER_CTRL,
WDT_AXP_FIXED_ENABLE_BIT,
WDT_AXP_FIXED_ENABLE_BIT);
@@ -138,16 +125,10 @@ static int armada375_wdt_clock_init(struct platform_device *pdev,
}
/* Mandatory fallback for proper devicetree backward compatibility */
- dev->clk = clk_get(&pdev->dev, NULL);
+ dev->clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(dev->clk))
return PTR_ERR(dev->clk);
- ret = clk_prepare_enable(dev->clk);
- if (ret) {
- clk_put(dev->clk);
- return ret;
- }
-
atomic_io_modify(dev->reg + TIMER_CTRL,
WDT_A370_RATIO_MASK(WDT_A370_RATIO_SHIFT),
WDT_A370_RATIO_MASK(WDT_A370_RATIO_SHIFT));
@@ -162,14 +143,9 @@ static int armadaxp_wdt_clock_init(struct platform_device *pdev,
int ret;
u32 val;
- dev->clk = of_clk_get_by_name(pdev->dev.of_node, "fixed");
+ dev->clk = devm_clk_get_enabled(&pdev->dev, "fixed");
if (IS_ERR(dev->clk))
return PTR_ERR(dev->clk);
- ret = clk_prepare_enable(dev->clk);
- if (ret) {
- clk_put(dev->clk);
- return ret;
- }
/* Fix the wdt and timer1 clock frequency to 25MHz */
val = WDT_AXP_FIXED_ENABLE_BIT | TIMER1_FIXED_ENABLE_BIT;
@@ -612,7 +588,7 @@ static int orion_wdt_probe(struct platform_device *pdev)
pdev->name, dev);
if (ret < 0) {
dev_err(&pdev->dev, "failed to request IRQ\n");
- goto disable_clk;
+ return ret;
}
}
@@ -624,34 +600,19 @@ static int orion_wdt_probe(struct platform_device *pdev)
0, pdev->name, dev);
if (ret < 0) {
dev_err(&pdev->dev, "failed to request IRQ\n");
- goto disable_clk;
+ return ret;
}
}
watchdog_set_nowayout(&dev->wdt, nowayout);
- ret = watchdog_register_device(&dev->wdt);
+ ret = devm_watchdog_register_device(&pdev->dev, &dev->wdt);
if (ret)
- goto disable_clk;
+ return ret;
pr_info("Initial timeout %d sec%s\n",
dev->wdt.timeout, nowayout ? ", nowayout" : "");
return 0;
-
-disable_clk:
- clk_disable_unprepare(dev->clk);
- clk_put(dev->clk);
- return ret;
-}
-
-static void orion_wdt_remove(struct platform_device *pdev)
-{
- struct watchdog_device *wdt_dev = platform_get_drvdata(pdev);
- struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev);
-
- watchdog_unregister_device(wdt_dev);
- clk_disable_unprepare(dev->clk);
- clk_put(dev->clk);
}
static void orion_wdt_shutdown(struct platform_device *pdev)
@@ -662,7 +623,6 @@ static void orion_wdt_shutdown(struct platform_device *pdev)
static struct platform_driver orion_wdt_driver = {
.probe = orion_wdt_probe,
- .remove = orion_wdt_remove,
.shutdown = orion_wdt_shutdown,
.driver = {
.name = "orion_wdt",
--
2.54.0
next reply other threads:[~2026-05-19 21:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-19 21:42 Rosen Penev [this message]
2026-05-19 22:08 ` [PATCH] watchdog: orion_wdt: Use devm APIs for clock and watchdog management sashiko-bot
2026-05-19 22:33 ` Guenter Roeck
2026-05-19 22:44 ` Rosen Penev
2026-05-19 23:10 ` Guenter Roeck
2026-05-19 23:19 ` Rosen Penev
2026-05-20 0:39 ` Guenter Roeck
2026-05-20 5:10 ` kernel test robot
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=20260519214229.16656-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=linux@roeck-us.net \
--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.