Skip to contentSkip to conversation

serial: sc16is7xx: Use devm_clk_get_optional_enabled() in sc16is7xx_probe()

PATCH NAK Markus Elfring 3 participants 4 messages Nov 19

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 serial: sc16is7xx: Use devm_clk_get_optional_enabled() in sc16is7xx_probe()

From: Markus Elfring <[email protected]>
Date: Thu, 19 Nov 2026 18:04:56 +0100

Reuse existing functionality from devm_clk_get_optional_enabled() instead of keeping duplicate source code.

The source code was transformed by using the Coccinelle software.

---
 drivers/tty/serial/sc16is7xx.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/tty/serial/sc16is7xx.c +1 -5
index dbf38825a78c..3af8ea93b34a 100644
@@ -1605,14 +1605,10 @@ int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype,
 		dev_dbg(dev,
 			"No interrupt pin definition, falling back to polling mode\n");
 
-	s->clk = devm_clk_get_optional(dev, NULL);
+	s->clk = devm_clk_get_optional_enabled(dev, NULL);
 	if (IS_ERR(s->clk))
 		return PTR_ERR(s->clk);
 
-	ret = clk_prepare_enable(s->clk);
-	if (ret)
-		return ret;
-
 	freq = clk_get_rate(s->clk);
 	if (freq == 0) {
 		if (uartclk)
Signature · 1 line
2.56.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] serial: sc16is7xx: double clk_disable_unprepare() in probe() and remove() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] serial: sc16is7xx: double clk_disable_unprepare() in probe() and remove()
--

commit af406fb81a7e34a89742ecfa2081aa070c5abb01
Author: Markus Elfring <[email protected]>

serial: sc16is7xx: Use devm_clk_get_optional_enabled() in sc16is7xx_probe()

This commit replaces devm_clk_get_optional() and clk_prepare_enable() in sc16is7xx_probe() with devm_clk_get_optional_enabled().

Quoted 10 lines
drivers/tty/serial/sc16is7xx.c +1 -1
index dbf38825a78ce..3af8ea93b34a4 100644
@@ -1605,14 +1605,10 @@ int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype,
 		dev_dbg(dev,
 			"No interrupt pin definition, falling back to polling mode\n");
 
-	s->clk = devm_clk_get_optional(dev, NULL);
+	s->clk = devm_clk_get_optional_enabled(dev, NULL);

drivers/tty/serial/sc16is7xx.c int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype, · line 1614

Quoted 10 lines
drivers/tty/serial/sc16is7xx.c +0 -4
 	if (IS_ERR(s->clk))
 		return PTR_ERR(s->clk);
 
-	ret = clk_prepare_enable(s->clk);
-	if (ret)
-		return ret;
-
 	freq = clk_get_rate(s->clk);
 	if (freq == 0) {
 		if (uartclk)

[Severity: High]
Does switching to devm_clk_get_optional_enabled() cause s->clk to be disabled and unprepared twice on probe failure or device removal?

The out_clk error path in sc16is7xx_probe() and sc16is7xx_remove() still call clk_disable_unprepare(s->clk) manually before devres runs its own release action, underflowing the clock enable and prepare reference counts.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Markus Elfring

Hi Markus,

Quoted 23 lines · On Thu, 19 Nov 2026 18:12:33 +0100 Markus Elfring <[email protected]> wrote:

From: Markus Elfring <[email protected]>
Date: Thu, 19 Nov 2026 18:04:56 +0100

Reuse existing functionality from devm_clk_get_optional_enabled() instead of keeping duplicate source code.

The source code was transformed by using the Coccinelle software.

---
 drivers/tty/serial/sc16is7xx.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/tty/serial/sc16is7xx.c +1 -1
index dbf38825a78c..3af8ea93b34a 100644
@@ -1605,14 +1605,10 @@ int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype,
 		dev_dbg(dev,
 			"No interrupt pin definition, falling back to polling mode\n");
 
-	s->clk = devm_clk_get_optional(dev, NULL);
+	s->clk = devm_clk_get_optional_enabled(dev, NULL);

drivers/tty/serial/sc16is7xx.c int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype, · line 1614

Quoted 10 lines
drivers/tty/serial/sc16is7xx.c +0 -4
 	if (IS_ERR(s->clk))
 		return PTR_ERR(s->clk);
 
-	ret = clk_prepare_enable(s->clk);
-	if (ret)
-		return ret;
-
 	freq = clk_get_rate(s->clk);
 	if (freq == 0) {
 		if (uartclk)

Nak, your patch is incomplete and in fact just duplicates, in part, what Xiangwu's patch does:

https://lore.kernel.org/all/[email protected]/

Signature · 1 line
Hugo Villeneuve