Re: [PATCH] mdio-airoha: fix refcount leak in airoha_mdio_probe()

From: Andrew Lunn

Date: Tue Jun 09 2026 - 06:01:59 EST


On Tue, Jun 09, 2026 at 09:07:29AM +0000, Wentao Liang wrote:
> 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. The devm cleanup does not assert the reset line, so
> the unbalanced deassert persists.
>
> Fix this by adding a reset_control_assert() call on the
> clk_set_rate() error path, matching the existing error handling
> for devm_of_mdiobus_register().
>
> Cc: stable@xxxxxxxxxxxxxxx
> Fixes: 67e3ba978361 ("net: mdio: Add MDIO bus controller for Airoha AN7583")
> Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
> ---
> drivers/net/mdio/mdio-airoha.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/mdio/mdio-airoha.c b/drivers/net/mdio/mdio-airoha.c
> index 52e7475121ea..030482b8318f 100644
> --- a/drivers/net/mdio/mdio-airoha.c
> +++ b/drivers/net/mdio/mdio-airoha.c
> @@ -245,8 +245,10 @@ static int airoha_mdio_probe(struct platform_device *pdev)
> freq = 2500000;
>
> ret = clk_set_rate(priv->clk, freq);
> - if (ret)
> + if (ret) {
> + reset_control_assert(priv->reset);
> return ret;
> + }
>
> ret = devm_of_mdiobus_register(dev, bus, dev->of_node);
> if (ret) {

devm_of_mdiobus_register() also calls reset_control_assert() on
error. So please put all the error cleanup handling at the end and use
goto.

Andrew

---
pw-bot: cr