Skip to contentSkip to conversation

net: mdio: airoha: fix reset control leak in error path

PATCH In review Wentao Liang 2 participants 2 messages Jun 22 – Jun 25

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

PATCH v2 1/1 net: mdio: airoha: fix reset control leak in error path

In airoha_mdio_probe(), after calling reset_control_deassert(), if clk_set_rate() fails, the function returns immediately without calling reset_control_assert(). This leaves the reset line deasserted and causes a reference count leak on shared reset controllers.

Fix this by reorganizing the error handling to use a goto label, ensuring reset_control_assert() is called on all error paths before returning.

Also add error checking for reset_control_deassert().

Fixes 67e3ba978361 ("net: mdio: Add MDIO bus controller for Airoha AN7583")
---
 drivers/net/mdio/mdio-airoha.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/net/mdio/mdio-airoha.c +7 -5
index 52e7475121ea..4c1b2415687c 100644
@@ -246,15 +246,17 @@ static int airoha_mdio_probe(struct platform_device *pdev)
 
 	ret = clk_set_rate(priv->clk, freq);
 	if (ret)
-		return ret;
+		goto err_reset_assert;
 
 	ret = devm_of_mdiobus_register(dev, bus, dev->of_node);
-	if (ret) {
-		reset_control_assert(priv->reset);
-		return ret;
-	}
+	if (ret)
+		goto err_reset_assert;
 
 	return 0;
+
+err_reset_assert:
+	reset_control_assert(priv->reset);
+	return ret;
 }
 
 static const struct of_device_id airoha_mdio_dt_ids[] = {
Signature · 1 line
2.39.5 (Apple Git-154)
#1 lore raw

Please, specify the target tree (probably, net) via a subject prefix. Also, looks like you are missing to many CCs [0]

[0]
https://netdev-ctrl.bots.linux.dev/logs/build/1114710/14639274/cc_maintainers/summary

Quoted 6 lines · Wentao Liang

In airoha_mdio_probe(), after calling reset_control_deassert(), if clk_set_rate() fails, the function returns immediately without calling reset_control_assert(). This leaves the reset line deasserted and causes a reference count leak on shared reset controllers.

Sashiko correctly points out that since the reset controller is exclusive, there is no refcount leak. [1]

So the problem is missing rstc->rcdev->ops->assert(rstc->rcdev, rstc->id) call. It would be great if you could describe, what problem this can cause.

Quoted 5 lines

Fix this by reorganizing the error handling to use a goto label, ensuring reset_control_assert() is called on all error paths before returning.

Also add error checking for reset_control_deassert().

Sashiko correctly points out you do not actually do this, which is fine, just update the commit message. [1]

[1] https://sashiko.dev/#/patchset/20260622115403.39772-1-vulab%40iscas.ac.cn

Quoted 37 lines
Fixes 67e3ba978361 ("net: mdio: Add MDIO bus controller for Airoha AN7583")
---
 drivers/net/mdio/mdio-airoha.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/net/mdio/mdio-airoha.c +7 -5
index 52e7475121ea..4c1b2415687c 100644
@@ -246,15 +246,17 @@ static int airoha_mdio_probe(struct platform_device *pdev)
 
 	ret = clk_set_rate(priv->clk, freq);
 	if (ret)
-		return ret;
+		goto err_reset_assert;
 
 	ret = devm_of_mdiobus_register(dev, bus, dev->of_node);
-	if (ret) {
-		reset_control_assert(priv->reset);
-		return ret;
-	}
+	if (ret)
+		goto err_reset_assert;
 
 	return 0;
+
+err_reset_assert:
+	reset_control_assert(priv->reset);
+	return ret;
 }
 
 static const struct of_device_id airoha_mdio_dt_ids[] = {
Signature · 1 line
2.39.5 (Apple Git-154)