Skip to contentSkip to conversation

clk: devres: make clock cleanup explicit on failure

PATCH In review Onur Özkan 3 participants 3 messages Sep 4 Common clk

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: devres: make clock cleanup explicit on failure

Use devm_add_action() and explicitly disable and unprepare the clock if registering the action fails to avoid smatch warning.

---
 drivers/clk/clk-devres.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/clk/clk-devres.c +4 -2
index 4cc3863bd7da..9ed9a7b7b23f 100644
@@ -123,9 +123,11 @@ 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)
+	ret = devm_add_action(dev, devm_clk_disable_unprepare, clk);
+	if (ret) {
+		clk_disable_unprepare(clk);
 		goto out_put_clk;
+	}
 
 	return clk;
 
Signature · 1 line
2.51.2
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Replaces devm_add_action_or_reset() with open-coded error handling to pacify a static analyzer. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Replaces devm_add_action_or_reset() with open-coded error handling to pacify a static analyzer. --

commit f91fcabb46a07cc1fa1a03a8bac1f236304fd974
Author: Onur Özkan <[email protected]>
Subject: clk: devres: make clock cleanup explicit on failure

This commit replaces the standard devm_add_action_or_reset() helper with devm_add_action() and an explicitly open-coded clock disable and unprepare sequence on failure. This change was made to address a smatch warning.

Quoted 5 lines
drivers/clk/clk-devres.c +0 -0
index 4cc3863bd7da9..9ed9a7b7b23f4 100644

drivers/clk/clk-devres.c struct clk *devm_clk_get_optional_enabled_with_rate(struct device *dev, · line 130

Quoted 10 lines
drivers/clk/clk-devres.c +4 -2
@@ -123,9 +123,11 @@ 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)
+	ret = devm_add_action(dev, devm_clk_disable_unprepare, clk);
+	if (ret) {
+		clk_disable_unprepare(clk);
 		goto out_put_clk;
+	}

[Severity: Low]
Is it necessary to open-code this cleanup logic in devm_clk_get_optional_enabled_with_rate() just to satisfy a static analyzer?

Replacing standard kernel abstractions like devm_add_action_or_reset() with manual error handling to pacify a false positive degrades code structure and reverts the benefits of the devres pattern.

Should the analyzer be fixed instead of open-coding the manual cleanup sequence here?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
Quoted 8 lines · On ven. 04 sept. 2026 at 08:01, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Replaces devm_add_action_or_reset() with open-coded error handling to pacify a static analyzer. --

commit f91fcabb46a07cc1fa1a03a8bac1f236304fd974
Author: Onur Özkan <[email protected]>
Subject: clk: devres: make clock cleanup explicit on failure

Quoted 6 lines

This commit replaces the standard devm_add_action_or_reset() helper with devm_add_action() and an explicitly open-coded clock disable and unprepare sequence on failure. This change was made to address a smatch warning.

Note that when you are fixing something, it usually needs a Fixes tag too.

Quoted 21 lines
Quoted 6 lines
drivers/clk/clk-devres.c +0 -0
index 4cc3863bd7da9..9ed9a7b7b23f4 100644

drivers/clk/clk-devres.c struct clk *devm_clk_get_optional_enabled_with_rate(struct device *dev, · line 130

Quoted 10 lines
drivers/clk/clk-devres.c +4 -2
@@ -123,9 +123,11 @@ 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)
+	ret = devm_add_action(dev, devm_clk_disable_unprepare, clk);
+	if (ret) {
+		clk_disable_unprepare(clk);
 		goto out_put_clk;
+	}

[Severity: Low]
Is it necessary to open-code this cleanup logic in devm_clk_get_optional_enabled_with_rate() just to satisfy a static analyzer?

Quoted 6 lines

Replacing standard kernel abstractions like devm_add_action_or_reset() with manual error handling to pacify a false positive degrades code structure and reverts the benefits of the devres pattern.

Should the analyzer be fixed instead of open-coding the manual cleanup sequence here?

I tend to agree. If we are missing something, please ellaborate.

Quoted 3 lines
Signature · 2 lines
-- 
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Signature · 1 line
Jerome