]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: stmmac: mdio: simplify MDC clock divisor lookup
authorRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Thu, 5 Mar 2026 10:42:37 +0000 (10:42 +0000)
committerJakub Kicinski <kuba@kernel.org>
Fri, 6 Mar 2026 23:39:09 +0000 (15:39 -0800)
As each lookup now iterates over each table in the same way, simplfy
the code to select the table, and then walk that table.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Tested-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Link: https://patch.msgid.link/E1vy6A9-0000000Btwp-0lxY@rmk-PC.armlinux.org.uk
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c

index 6292911fb54b68ce504be29670f7e5a2cb34a05b..c9f0b8b601d272d490cde2ed3c162db19d412ea4 100644 (file)
@@ -535,6 +535,7 @@ static const struct stmmac_clk_rate stmmac_xgmac_csr_to_mdc[] = {
  */
 static u32 stmmac_clk_csr_set(struct stmmac_priv *priv)
 {
+       const struct stmmac_clk_rate *rates;
        unsigned long clk_rate;
        u32 value = ~0;
        int i;
@@ -548,25 +549,17 @@ static u32 stmmac_clk_csr_set(struct stmmac_priv *priv)
         * the frequency of clk_csr_i. So we do not change the default
         * divider.
         */
-       for (i = 0; stmmac_std_csr_to_mdc[i].rate; i++)
-               if (clk_rate > stmmac_std_csr_to_mdc[i].rate)
-                       break;
-       if (stmmac_std_csr_to_mdc[i].cr != (u8)~0)
-               value = stmmac_std_csr_to_mdc[i].cr;
-
-       if (priv->plat->flags & STMMAC_FLAG_HAS_SUN8I) {
-               for (i = 0; stmmac_sun8i_csr_to_mdc[i].rate; i++)
-                       if (clk_rate > stmmac_sun8i_csr_to_mdc[i].rate)
-                               break;
-               value = stmmac_sun8i_csr_to_mdc[i].cr;
-       }
+       rates = stmmac_std_csr_to_mdc;
+       if (priv->plat->flags & STMMAC_FLAG_HAS_SUN8I)
+               rates = stmmac_sun8i_csr_to_mdc;
+       if (priv->plat->core_type == DWMAC_CORE_XGMAC)
+               rates = stmmac_xgmac_csr_to_mdc;
 
-       if (priv->plat->core_type == DWMAC_CORE_XGMAC) {
-               for (i = 0; stmmac_xgmac_csr_to_mdc[i].rate; i++)
-                       if (clk_rate > stmmac_xgmac_csr_to_mdc[i].rate)
-                               break;
-               value = stmmac_xgmac_csr_to_mdc[i].cr;
-       }
+       for (i = 0; rates[i].rate; i++)
+               if (clk_rate > rates[i].rate)
+                       break;
+       if (rates[i].cr != (u8)~0)
+               value = rates[i].cr;
 
        return value;
 }