* [PATCH v1] clk: devres: fix cleanup in devm_clk_get_optional_enabled_with_rate()
@ 2026-08-01 11:16 Onur Özkan
2026-08-03 13:28 ` Brian Masney
0 siblings, 1 reply; 3+ messages in thread
From: Onur Özkan @ 2026-08-01 11:16 UTC (permalink / raw)
To: linux-clk, linux-kernel
Cc: mturquette, sboyd, bmasney, daniel.almeida, Onur Özkan
devm_clk_get_optional_enabled_with_rate() registers its cleanup action
before setting the clock rate. If setting the rate fails, it attempts to
disable and unprepare a clock that was never enabled. This issue was
spotted while reviewing "rust: clk: add devres-managed clks" [1].
Register the cleanup action only after successfully preparing and enabling
the clock.
[1]: https://lore.kernel.org/rust-for-linux/20260706-clk-type-state-v5-3-67c5f326a16c@collabora.com
Fixes: 9934a1bd45b2 ("clk: provide devm_clk_get_optional_enabled_with_rate()")
Signed-off-by: Onur Özkan <work@onurozkan.dev>
---
drivers/clk/clk-devres.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/clk/clk-devres.c b/drivers/clk/clk-devres.c
index 994d5bc5168b..697d102449c1 100644
--- a/drivers/clk/clk-devres.c
+++ b/drivers/clk/clk-devres.c
@@ -99,6 +99,11 @@ struct clk *devm_clk_get_optional_enabled(struct device *dev, const char *id)
}
EXPORT_SYMBOL_GPL(devm_clk_get_optional_enabled);
+static void devm_clk_disable_unprepare(void *data)
+{
+ clk_disable_unprepare(data);
+}
+
struct clk *devm_clk_get_optional_enabled_with_rate(struct device *dev,
const char *id,
unsigned long rate)
@@ -106,8 +111,7 @@ struct clk *devm_clk_get_optional_enabled_with_rate(struct device *dev,
struct clk *clk;
int ret;
- clk = __devm_clk_get(dev, id, clk_get_optional, NULL,
- clk_disable_unprepare);
+ clk = devm_clk_get_optional(dev, id);
if (IS_ERR(clk))
return ERR_CAST(clk);
@@ -119,6 +123,10 @@ struct clk *devm_clk_get_optional_enabled_with_rate(struct device *dev,
if (ret)
goto out_put_clk;
+ ret = devm_add_action_or_reset(dev, devm_clk_disable_unprepare, clk);
+ if (ret)
+ goto out_put_clk;
+
return clk;
out_put_clk:
--
2.51.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v1] clk: devres: fix cleanup in devm_clk_get_optional_enabled_with_rate()
2026-08-01 11:16 Onur Özkan
@ 2026-08-03 13:28 ` Brian Masney
0 siblings, 0 replies; 3+ messages in thread
From: Brian Masney @ 2026-08-03 13:28 UTC (permalink / raw)
To: Onur Özkan
Cc: linux-clk, linux-kernel, mturquette, sboyd, daniel.almeida
On Sat, Aug 01, 2026 at 02:16:34PM +0300, Onur Özkan wrote:
> devm_clk_get_optional_enabled_with_rate() registers its cleanup action
> before setting the clock rate. If setting the rate fails, it attempts to
> disable and unprepare a clock that was never enabled. This issue was
> spotted while reviewing "rust: clk: add devres-managed clks" [1].
>
> Register the cleanup action only after successfully preparing and enabling
> the clock.
>
> [1]: https://lore.kernel.org/rust-for-linux/20260706-clk-type-state-v5-3-67c5f326a16c@collabora.com
>
> Fixes: 9934a1bd45b2 ("clk: provide devm_clk_get_optional_enabled_with_rate()")
> Signed-off-by: Onur Özkan <work@onurozkan.dev>
Reviewed-by: Brian Masney <bmasney@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v1] clk: devres: fix cleanup in devm_clk_get_optional_enabled_with_rate()
@ 2026-08-08 16:53 kernel test robot
0 siblings, 0 replies; 3+ messages in thread
From: kernel test robot @ 2026-08-08 16:53 UTC (permalink / raw)
To: oe-kbuild; +Cc: lkp, Dan Carpenter
BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20260801111637.304590-1-work@onurozkan.dev>
References: <20260801111637.304590-1-work@onurozkan.dev>
TO: "Onur Özkan" <work@onurozkan.dev>
TO: linux-clk@vger.kernel.org
TO: linux-kernel@vger.kernel.org
CC: mturquette@baylibre.com
CC: sboyd@kernel.org
CC: bmasney@redhat.com
CC: daniel.almeida@collabora.com
CC: "Onur Özkan" <work@onurozkan.dev>
Hi Onur,
kernel test robot noticed the following build warnings:
[auto build test WARNING on linux-review/Daniel-Almeida/rust-clk-use-the-type-state-pattern/20260706-224926]
url: https://github.com/intel-lab-lkp/linux/commits/Onur-zkan/clk-devres-fix-cleanup-in-devm_clk_get_optional_enabled_with_rate/20260805-211528
base: https://github.com/intel-lab-lkp/linux Daniel-Almeida/rust-clk-use-the-type-state-pattern/20260706-224926
patch link: https://lore.kernel.org/r/20260801111637.304590-1-work%40onurozkan.dev
patch subject: [PATCH v1] clk: devres: fix cleanup in devm_clk_get_optional_enabled_with_rate()
:::::: branch date: 3 days ago
:::::: commit date: 3 days ago
config: parisc-randconfig-r071-20260808 (https://download.01.org/0day-ci/archive/20260809/202608090025.dwxdfqFr-lkp@intel.com/config)
compiler: hppa-linux-gcc (GCC) 11.5.0
smatch: v0.5.0-9187-g5189e3fb
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/202608090025.dwxdfqFr-lkp@intel.com/
smatch warnings:
drivers/clk/clk-devres.c:134 devm_clk_get_optional_enabled_with_rate() warn: 'clk' from clk_prepare_enable() not released on lines: 134.
vim +/clk +134 drivers/clk/clk-devres.c
1c34a54a924f326 Onur Özkan 2026-08-01 106
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 107 struct clk *devm_clk_get_optional_enabled_with_rate(struct device *dev,
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 108 const char *id,
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 109 unsigned long rate)
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 110 {
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 111 struct clk *clk;
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 112 int ret;
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 113
1c34a54a924f326 Onur Özkan 2026-08-01 114 clk = devm_clk_get_optional(dev, id);
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 115 if (IS_ERR(clk))
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 116 return ERR_CAST(clk);
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 117
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 118 ret = clk_set_rate(clk, rate);
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 119 if (ret)
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 120 goto out_put_clk;
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 121
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 122 ret = clk_prepare_enable(clk);
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 123 if (ret)
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 124 goto out_put_clk;
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 125
1c34a54a924f326 Onur Özkan 2026-08-01 126 ret = devm_add_action_or_reset(dev, devm_clk_disable_unprepare, clk);
1c34a54a924f326 Onur Özkan 2026-08-01 127 if (ret)
1c34a54a924f326 Onur Özkan 2026-08-01 128 goto out_put_clk;
1c34a54a924f326 Onur Özkan 2026-08-01 129
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 130 return clk;
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 131
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 132 out_put_clk:
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 133 devm_clk_put(dev, clk);
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 @134 return ERR_PTR(ret);
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 135 }
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 136 EXPORT_SYMBOL_GPL(devm_clk_get_optional_enabled_with_rate);
9934a1bd45b2b03 Bartosz Golaszewski 2024-08-05 137
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-08 16:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-08 16:53 [PATCH v1] clk: devres: fix cleanup in devm_clk_get_optional_enabled_with_rate() kernel test robot
-- strict thread matches above, loose matches on Subject: below --
2026-08-01 11:16 Onur Özkan
2026-08-03 13:28 ` Brian Masney
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.