Re: [PATCH net] net: mdio: mdio-bcm-unimac: Correct rate fallback logic
From: Simon Horman
Date: Wed Jul 30 2025 - 10:33:17 EST
On Tue, Jul 29, 2025 at 02:31:48PM -0700, Florian Fainelli wrote:
> In case the rate for the parent clock is zero, make sure that we still
> fallback to using a fixed rate for the divider calculation, otherwise we
> simply ignore the desired MDIO bus clock frequency which can prevent us
> from interfacing with Ethernet PHYs properly.
>
> Fixes: ee975351cf0c ("net: mdio: mdio-bcm-unimac: Manage clock around I/O accesses")
> Signed-off-by: Florian Fainelli <florian.fainelli@xxxxxxxxxxxx>
> ---
> drivers/net/mdio/mdio-bcm-unimac.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/mdio/mdio-bcm-unimac.c b/drivers/net/mdio/mdio-bcm-unimac.c
> index b6e30bdf5325..9c0a11316cfd 100644
> --- a/drivers/net/mdio/mdio-bcm-unimac.c
> +++ b/drivers/net/mdio/mdio-bcm-unimac.c
> @@ -209,10 +209,9 @@ static int unimac_mdio_clk_set(struct unimac_mdio_priv *priv)
> if (ret)
> return ret;
>
> - if (!priv->clk)
> + rate = clk_get_rate(priv->clk);
> + if (!priv->clk || !rate)
If priv->clk is NULL then drivers/clk/clk.c:clk_get_rate()
(are there other relevant implementations?) will return 0.
So I think the condition above is tautological, and could be expressed as:
if (!rate)
> rate = 250000000;
> - else
> - rate = clk_get_rate(priv->clk);
>
> div = (rate / (2 * priv->clk_freq)) - 1;
> if (div & ~MDIO_CLK_DIV_MASK) {
> --
> 2.34.1
>
>