From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 EA0213C5837 for ; Sat, 22 Aug 2026 15:53:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787413992; cv=none; b=AsBWZFbOSUMOR7PNrbjW1G/XLfjE+8GYBN4kDK8wvU/Bu8bP01xN1Sz5lzYHUbrEBDXNcnif0AdI+k80xRSevJyCqymeVD33wBkIMK1HSfm01PvU9USsG6cwTVTDVBe67e41NDFS4ITCoSFUyMKy2rfMPvzExwb51d10g18CSV4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787413992; c=relaxed/simple; bh=bwFb8+8zfaie+LAvs8/7XUIsL9MQzN7tXA0AU8G3HCs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B4BS95q1XXZgXLNfR8mAGvKt2H9bLAoiVjrlz2OcjvWrxbm6rbyDQWDA+suceV9mR36egDDYWoqP0+t2GjalWvmwAal8pa3LT3PqVM9tVGuRlL5joBQT2+jkEeVU2Sk9qu9PutL4i44VKENUOOwJ2kYaJQoDS5y2mU8PEBXAzro= 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=CQsgwUzc; arc=none smtp.client-ip=209.85.208.49 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="CQsgwUzc" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-6a422090b2fso3095978a12.0 for ; Sat, 22 Aug 2026 08:53:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lex.la; s=google; t=1787413989; x=1788018789; 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=IThcaUItiGTT1yNVv9ohDD3OMYEp3sYsB42Cn7lxU0E=; b=CQsgwUzcWtIsP99cWomQoR75dBMdxvYmegtT1H4M3qROq85FM3Q7oYe6+lIQGfr9WJ J+d5z5gbQnXnic4ic/KFVJAyyIhqX6GtUPieOhj/+wSJ8/9WFsQCSzxIG4H23Uej55QL ePLDGhrOwoA+qJWdJOSciYGsNqTO+a69Jr9OKiOLZYa0CXz3Ug3qEkHrm5/7vR+YIeqj TchKKbRf6ydAxEf0KdcctSz8MGwYHcCNLm9CRT38PGgVnJ1qtvcKxMvPhf7dsgG+1FlS P429gCZWA9InGzLkaEdGL866bmC9b+Vv8Q0Eu5nDAM+k/pZjnVgelP3zbeHTFHcrLoiK 0Xyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787413989; x=1788018789; 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=IThcaUItiGTT1yNVv9ohDD3OMYEp3sYsB42Cn7lxU0E=; b=Y6Vf2Brr3f9sjq0Xt9gGL8Uey7YOlOvWM96U6oapjEe34PWpjnuRjZPtrEQglWgtLt 5qfuB1Vxx0k+7vnOeY4M+cxkHMrOxMSe/hUNvMv36YEaueqP7DOMNLS7tKLp/2ckpvlq OPKFxKQjKhRsuftWn2t/5YpqpqiTYX1gcl9ap4Vm2ZHWHf8SB1XlpIGE9noPwU2Unei1 R4lA2K49fRQoZyZg4fCSmEZK6+P0sfmDPOq8LpI02ysKDFuT8/Yf2Oy7mfO48astUhn6 ljxoyb9pen5rQmmEpvovYn49WOtA1fw6kzgmCVfpH1/KqRYN3jVq6qRy3Cu7sKy+mIUn sppQ== X-Forwarded-Encrypted: i=1; AHgh+Rr/oEtSxDu4elGkJ13yzZMCQyvJQ53f8P7gTIoZmjfi/QYkrlu50NDFnqdHU9etsoHw9z/yim8kWXlpTSA=@vger.kernel.org X-Gm-Message-State: AFuF++n0vMzGA+mCDBMA6odqE2EPSN15kXkyRLyZYSsadSSuAZO5s4yP IE29Kg7RuXWwE0dFHjQUG1b5NS+ojEqbdgSG/+WACiEiLKR/NIZ8DGJjwGtQ66vcqOM= X-Gm-Gg: AR+sD12mCh6GmofYFQa+NG1sV+jWG9b/rDHg25QidoA1w9MyJ56JXcwL0kdbXIMSWO2 jnt3QHT2zTvj96LjJsl6hbvRdEMWm3hpBRUuHwQII+dgR4wCpjMBmoEnS/cDVLhY87hMR4ORZJq qVW0v1bi4ixWW72YaGrO//8CNQY+0Z9eKvXxIoSlMQJymyVetR/nkngcr9ZPrMkxRzh3jibyM5B xgA8eibKERkArKsxE8BCH3mSRMmZmF5jSVgerRGQcDozkrTFpsS/cqK+NaTkvmQoQ/Ve06mmASN JUGcIVqL2XFBG+6HNmfVId38Opavq2YT4SfU/SMmVO0np+1R9hvg91Akz8rsAQr2nQUPBz2iMdL X42J/MVrllMsAz9GvTdIxjGy5Gh1gU9Allx/jFDGBjqf14PECDJvopS7uV0iPGZEdFtKd5Ag1et r1IigKJdAOyUjJJM1DwQU+PQDw8MFydJHKFp6UFYP8SAgKS1wqMxnMwdO9alLnEtvhKog2rQ== X-Received: by 2002:a05:6402:444a:b0:698:351c:979c with SMTP id 4fb4d7f45d1cf-6a42f16f016mr17302770a12.2.1787413988818; Sat, 22 Aug 2026 08:53:08 -0700 (PDT) Received: from ownbook.home.lex.la ([84.17.55.225]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6a3ff16c546sm12396250a12.21.2026.08.22.08.53.07 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 22 Aug 2026 08:53:08 -0700 (PDT) From: Aleksei Sviridkin To: Andrew Lunn , Vladimir Oltean , Heiner Kallweit , Russell King Cc: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Aleksei Sviridkin Subject: [PATCH net-next 1/3] net: phylink: unwind the PHY binding when bringup fails late Date: Sat, 22 Aug 2026 18:52:57 +0300 Message-ID: <20260822155259.87146-2-f@lex.la> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260822155259.87146-1-f@lex.la> References: <20260822155259.87146-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 a device reference and two module references that were only ever taken once. Clear the binding on the failure path, the same three fields phylink_disconnect_phy() clears, under the same locks. The PHY-side fields are left to phy_detach(), which every caller already runs on this path. Signed-off-by: Aleksei Sviridkin --- Reachability The failing step needs pl->mac_supports_eee_ops, i.e. a MAC whose phylink ops implement the LPI callbacks; mt7530 is one, and on the board I tested ethtool --show-eee returns -EOPNOTSUPP, which is what phylink reports when mac_supports_eee_ops is set and mac_supports_eee is not, so that tail runs on every bringup there. The error itself is an MDIO transaction failure inside phy_eee_rx_clock_stop(), which cannot be produced deliberately, so this patch is compile-tested and the series it belongs to ran on hardware with it in place. The double-detach path needs a port that outlives a failed connect, which is what patch 3 introduces; before that, DSA destroyed the port immediately and the stale pointer went with it. drivers/net/phy/phylink.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 5b8e95690..9d403ff1b 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -2197,6 +2197,18 @@ 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); + 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); + mutex_unlock(&pl->phydev_mutex); + } + return ret; } -- 2.43.0