]> www.infradead.org Git - users/hch/misc.git/commitdiff
net: stmmac: ptp: improve handling of aux_ts_lock lifetime
authorRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Thu, 11 Sep 2025 11:09:37 +0000 (12:09 +0100)
committerJakub Kicinski <kuba@kernel.org>
Sun, 14 Sep 2025 19:00:54 +0000 (12:00 -0700)
The aux_ts_lock mutex is only required while the PTP clock has been
successfully registered.

stmmac_ptp_register() does not return any errors (as we don't wish to
prevent the netdev being opened if PTP fails), stmmac_ptp_unregister()
was coded to allow it to be called irrespective of whether PTP was
successfully registered or not.

Arrange for the aux_ts_lock mutex to be destroyed if the PTP clock
is not functional during stmmac_ptp_register(), and only destroy it
in stmmac_ptp_unregister() if we had a PTP clock registered.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c

index 69bd8ace139cd8411e49cf11e60248910272cf98..993ff4e87e5570a31f3522dec71ac4478ced7360 100644 (file)
@@ -370,8 +370,12 @@ void stmmac_ptp_register(struct stmmac_priv *priv)
        if (IS_ERR(priv->ptp_clock)) {
                netdev_err(priv->dev, "ptp_clock_register failed\n");
                priv->ptp_clock = NULL;
-       } else if (priv->ptp_clock)
+       }
+
+       if (priv->ptp_clock)
                netdev_info(priv->dev, "registered PTP clock\n");
+       else
+               mutex_destroy(&priv->aux_ts_lock);
 }
 
 /**
@@ -387,7 +391,7 @@ void stmmac_ptp_unregister(struct stmmac_priv *priv)
                priv->ptp_clock = NULL;
                pr_debug("Removed PTP HW clock successfully on %s\n",
                         priv->dev->name);
-       }
 
-       mutex_destroy(&priv->aux_ts_lock);
+               mutex_destroy(&priv->aux_ts_lock);
+       }
 }