From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A2ED364E9A for ; Mon, 24 Aug 2026 02:40:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787539247; cv=none; b=lRdrsd1XKosgn4xB2M3VbiafRbYzlL8fIp9cmmN+ueZOBk5kRCX8XEKnrE7yx9f7rI63OqLME/0Q8PUK3DMs50OVHNnqRuiwPbC1/u6lNY51bv4dFRB89hyEZTSp7VDL/lJN/WKQ/tqxLs3T1Yr6txR7An1lxq13WxvL4ETAK8s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787539247; c=relaxed/simple; bh=+3Wg4hev+RdHrstqfxAhur7flQ+aLkM6Csxu2Qs/c+E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BMhv8iVqRwTtYhvHoKfm/QooYlZtl9WCwBFxJUpirpEmoZHT24Ha696BqYUvu0MdElD5nRNo3zXGXYXMvRR11mg/sZ2sHqAFo533UdgxUam7TX1VPHWZUkXUUbKOP3+dPR4CIYfd461BZz0qPxm2W4ZKkdDNa5ad9wrONjyNDik= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=lex.la; spf=pass smtp.mailfrom=lex.la; dkim=pass (2048-bit key) header.d=lex.la header.i=@lex.la header.b=hoaR3SL1; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=lex.la Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lex.la Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lex.la header.i=@lex.la header.b="hoaR3SL1" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-c15d3cd51b2so443297266b.3 for ; Sun, 23 Aug 2026 19:40:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lex.la; s=google; t=1787539240; x=1788144040; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=bcLtMagmgkZbYwvDV0YgYY3BoJUyu7By6WJbKfTcwDY=; b=hoaR3SL1Ww1/mQRiIW6LS81s/G9uB68JMqWDoUUbSe8mbkRa2SvHQl2Q0wmGzhQb45 qe6QNSoUeUjG26vBliBqpmownUa8g8bEcD/0IwkbQctugivA4cerBAGVDdkOKW2sNXPM z3ZDOf+rv4F8tIeJWKjFS5n/57SNe1zErVUrHP5caWMLRcRaAL14GFkyVCKHGcp6jp4s 4fkUXGRrFJrQbekt1QwC50zdZ29hT7gGRJGVgyDI/W0GmvxOXOqkWPY+i5Qt1IhoYc7R R1HLdDCpkWLS7s0uRSIeimnJsa91adebE8R/zLc3435J2M8zv1HIeHU8S9noY8b9Gyr2 Jbuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787539240; x=1788144040; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=bcLtMagmgkZbYwvDV0YgYY3BoJUyu7By6WJbKfTcwDY=; b=mmLMbl/P6sygYrd5JNGqfDzCMN+tYBKgVbFC220fZQbXgpAw2nDU20uVror7Rv5Nve LHOeb13812sWlS224TAufW3V931YXBRnxEaGKmA40nw/sH6CNg1AQnuAw1EI05JcFPzP E5KYQuk2yX+qp3IhMLR5+p6AEFFgQebg3gwDWDXX1F+heFeu/k00eHwplALb/Srgw0+q xGAAjYfPFaXPY9GdDYtdaxB49+BIQmXQuY1PJDPMpOYdteCnBdpPZOOYFWCwIBTWqgjm ScVnCq+KXkJdw1f1KRl0/cp6fme6w5f6o6LSGxfk4WIZO6vVqBDIC93hBY1Ie7fKJ1Ga AuzA== X-Forwarded-Encrypted: i=1; AHgh+RoamcTtvBVbc43Z9O4/78sgoiMys5ID+6TI1kJ3URT74DbChMb22gQ8ehkS/DzFiGQJh/Yb3NFg2IBCATU=@vger.kernel.org X-Gm-Message-State: AFuF++nWBWzzY/eY8opBtT51hm3STPuDO5eXrmvgIb7cD+PfnIygh7FF QY84T/ahvp/5kdqsTNzj8HCllJKld3raRuhWQn01coFqjPV69u/6E9b9x6vVj4HU5xU= X-Gm-Gg: AR+sD12AQGrroGAXBQugyrdyKumK9kK+9mscloIReI08JwPgtQUfiME1rLrbMwiz0BS +uf9LvR95CAp8Q9wiMrocNGmb83MlhCEjU0h/fevYHEIZgeJ1Mo8QrHeDHybGl8LqTtLw9qJdqQ AxauQQm+HPeA+fv8lZUEgYPhbUZBXnEm6qc2sh3zpVryiyNqQM9HtnHFgY3oMoSXoiF7YhSIeyH 67ciMuNAwXNXix9Y3UkNQXL/C0Sgfs+f9ck8vKfL61pPi492K8x+GagqQWdXejeKLrpxLAwpoQz 4was01nglbATVLH0WN1MIVKV7zD8OKXYj4FrgHUCGWFp7f4OLnVx/yyI2HRzIj0KuWduSXywiAf ZakraIj9pcIJdXdEAuUdpVSFTJpHs/2nuZKTOR0y78UOgiOoKsJlfWUlZtdd6/uhx2KIRFJ01GO HBF4+oNyqUB4L6xVueh267Kzh2/emmmrdDLFivsr0/eUMe8Duc1hCYYBb4 X-Received: by 2002:a17:907:a089:b0:c21:450d:cd88 with SMTP id a640c23a62f3a-c24924b8000mr1721172966b.6.1787539240649; Sun, 23 Aug 2026 19:40:40 -0700 (PDT) Received: from ownbook ([195.181.160.194]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c24966f8f2asm1051909566b.36.2026.08.23.19.40.36 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 23 Aug 2026 19:40:40 -0700 (PDT) From: Aleksei Sviridkin To: Andrew Lunn , Heiner Kallweit , Russell King Cc: Aleksei Sviridkin , Vladimir Oltean , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 1/2] net: phylink: unwind the PHY binding when bringup fails late Date: Mon, 24 Aug 2026 05:40:27 +0300 Message-ID: <20260824024029.41310-2-f@lex.la> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260824024029.41310-1-f@lex.la> References: <20260824024029.41310-1-f@lex.la> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit phylink_bringup_phy() records the PHY in pl->phydev before its last fallible step: on a MAC whose phylink ops implement LPI, phy_eee_rx_clock_stop() can fail with a real MDIO error. The callers unwind with phy_detach(), which knows nothing about pl->phydev, so a pointer to a PHY that is no longer attached outlives the failed connect. What that costs depends on how the caller got here. phylink_connect_phy() and the SFP path go through phylink_attach_phy(), which refuses to attach while pl->phydev is set and turns a transient MDIO error into a permanent -EBUSY. phylink_fwnode_phy_connect() has no such check, so a later connect overwrites the stale pointer and hides the problem. A disconnect does not: phylink_disconnect_phy() hands that pointer to phy_disconnect(), and the second phy_detach() on the same PHY drops references the first one already released. Clear the binding on the failure path. This is the same operation phylink_disconnect_phy() performs, so both now share a helper. The PHY-side fields are left to phy_detach(), which every caller already runs on this path. Fixes: 03abf2a7c654 ("net: phylink: add EEE management") Signed-off-by: Aleksei Sviridkin --- drivers/net/phy/phylink.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 5b8e956902fb..a55e4a64028f 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -2083,6 +2083,18 @@ static int phylink_validate_phy(struct phylink *pl, struct phy_device *phy, return phylink_validate(pl, supported, state); } +/* Disassociate @phy from @pl. Caller must hold pl->phydev_mutex. */ +static void phylink_clear_phydev(struct phylink *pl, struct phy_device *phy) +{ + mutex_lock(&phy->lock); + mutex_lock(&pl->state_mutex); + pl->phydev = NULL; + pl->phy_enable_tx_lpi = false; + pl->mac_tx_clk_stop = false; + mutex_unlock(&pl->state_mutex); + mutex_unlock(&phy->lock); +} + static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy, phy_interface_t interface) { @@ -2197,6 +2209,12 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy, if (ret == 0 && phy_interrupt_is_valid(phy)) phy_request_interrupt(phy); + if (ret) { + mutex_lock(&pl->phydev_mutex); + phylink_clear_phydev(pl, phy); + mutex_unlock(&pl->phydev_mutex); + } + return ret; } @@ -2347,15 +2365,8 @@ void phylink_disconnect_phy(struct phylink *pl) mutex_lock(&pl->phydev_mutex); phy = pl->phydev; - if (phy) { - mutex_lock(&phy->lock); - mutex_lock(&pl->state_mutex); - pl->phydev = NULL; - pl->phy_enable_tx_lpi = false; - pl->mac_tx_clk_stop = false; - mutex_unlock(&pl->state_mutex); - mutex_unlock(&phy->lock); - } + if (phy) + phylink_clear_phydev(pl, phy); mutex_unlock(&pl->phydev_mutex); if (phy) { -- 2.55.0