mlxsw_sp1_ptp_mtpppc_update() increases the global parsing depth reference count before writing the MTPPPC register when timestamping is enabled for the first time. If the register write fails, the reference count remains elevated even though no timestamping configuration was installed, and nothing will ever release it. Drop the reference count again when the write fails. Also only drop it when disabling timestamping after the write succeeded, so that the reference count always matches the programmed state. Fixes: c6b36bdd04b5 ("mlxsw: spectrum_ptp: Increase parsing depth when PTP is enabled") Cc: stable@vger.kernel.org Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex Signed-off-by: Wentao Liang --- drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c index 9c5862f4e16a..0db77af4828f 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c @@ -1190,6 +1190,7 @@ static int mlxsw_sp1_ptp_mtpppc_update(struct mlxsw_sp_port *mlxsw_sp_port, struct mlxsw_sp_port *tmp; u16 orig_ing_types = 0; u16 orig_egr_types = 0; + bool depth_inc = false; int err; int i; @@ -1214,12 +1215,21 @@ static int mlxsw_sp1_ptp_mtpppc_update(struct mlxsw_sp_port *mlxsw_sp_port, netdev_err(mlxsw_sp_port->dev, "Failed to increase parsing depth"); return err; } + depth_inc = true; } + + err = mlxsw_sp1_ptp_mtpppc_set(mlxsw_sp_port->mlxsw_sp, + ing_types, egr_types); + if (err) { + if (depth_inc) + mlxsw_sp_parsing_depth_dec(mlxsw_sp); + return err; + } + if (!(ing_types || egr_types) && (orig_ing_types || orig_egr_types)) mlxsw_sp_parsing_depth_dec(mlxsw_sp); - return mlxsw_sp1_ptp_mtpppc_set(mlxsw_sp_port->mlxsw_sp, - ing_types, egr_types); + return 0; } static bool mlxsw_sp1_ptp_hwtstamp_enabled(struct mlxsw_sp_port *mlxsw_sp_port) -- 2.34.1