diff mbox series

[net-next,1/6] net: phylink: reset PCS-Phylink double reference on phylink_stop

Message ID 20250318235850.6411-2-ansuelsmth@gmail.com (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series net: pcs: Introduce support for PCS OF | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 1 maintainers not CCed: andrew@lunn.ch
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 9 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 17 this patch: 17
netdev/source_inline success Was 0 now: 0

Commit Message

Christian Marangi March 18, 2025, 11:58 p.m. UTC
On calling phylink_stop, the double reference between PCS and Phylink is
never reset. This is OK in the current rudimental implementation of PCS
as current PCS driver doesn't autonomously handle link termination (or
actually doesn't handle removal of the PCS driver at all)

But this immediately became problematic if the PCS driver makes use of
this double reference to track if the PCS have an actual user attached.
If a driver makes use of this and the double reference is not reset, the
driver might erroneously detect the PCS have a user and execute stop
operation even if not actually used. (causing unwanted link termination)

To permit PCS driver to detect this correctly, and to better handle this
similar to how it done with phylink_major_config, set to NULL the double
reference between PCS and Phylink on phylink_stop.

On phylink_major_config, PCS is always refreshed by calling
mac_select_pcs hence it's save to always reset it in phylink_stop.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/net/phy/phylink.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 76b1a329607b..eef1712ec22c 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -2589,6 +2589,9 @@  void phylink_stop(struct phylink *pl)
 	pl->pcs_state = PCS_STATE_DOWN;
 
 	phylink_pcs_disable(pl->pcs);
+	if (pl->pcs)
+		pl->pcs->phylink = NULL;
+	pl->pcs = NULL;
 }
 EXPORT_SYMBOL_GPL(phylink_stop);