Messages in this thread |  | | Date | Wed, 28 May 2025 10:06:23 +0200 | | Subject | Re: [PATCH v2] net: stmmac: add explicit check and error on invalid PTP clock rate | | From | Alexis Lothoré <> |
| |
Hey Maxime,
On Tue May 27, 2025 at 6:31 PM CEST, Maxime Chevallier wrote: > Hi Alexis, > > On Tue, 27 May 2025 08:33:44 +0200 > Alexis Lothoré <alexis.lothore@bootlin.com> wrote:
[...]
>> + if (!priv->plat->clk_ptp_rate) { >> + netdev_err(priv->dev, "Invalid PTP clock rate"); >> + return -EINVAL; >> + } >> + >> stmmac_config_hw_tstamping(priv, priv->ptpaddr, systime_flags); >> priv->systime_flags = systime_flags; > > This may be some nitpick that can be addressed at a later point, but we > now have a guarantee that when stmmac_ptp_register() gets called, > priv->ptp_clk_rate is non-zero, right ? If so, we can drop the test in > said function : > > if (priv->plat->has_gmac4 && priv->plat->clk_ptp_rate) > priv->plat->cdc_error_adj = (2 * NSEC_PER_SEC) / priv->plat->clk_ptp_rate;
You are right, my series makes this check a duplicate, I'll remove it.
> There is another spot in the code, like in the EST handling, where we > divide by priv->plat->ptp_clk_rate : > > stmmac_adjust_time(...) > stmmac_est_configure(priv, priv, priv->est, > priv->plat->clk_ptp_rate) > .est_configure() > ctrl |= ((NSEC_PER_SEC / ptp_rate) [...] > > Maybe we should fail EST configuration as well if ptp_clk_rate is 0 > (probably in stmmac_tc.c's tc_taprio_configure or in the > .est_configure). That can be a step for later as well, as I don't know > if the setup you found this bug on even supports taprio/EST, and setups > that do didn't seem to encounter the bug yet.
I guess you are right as well, it may not make sense to try to configure EST if we have a bogus clk_ptp_rate value. est_configure seems to be called in both tc_taprio_configure and stmmac_adjust_time, so I'll add the check in est_configure.
Thanks,
Alexis
-- Alexis Lothoré, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
|  |