From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD9253DBD6E for ; Mon, 9 Mar 2026 15:28:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773070094; cv=none; b=skG57IonZHgrrB4cU+R/u5c/BNxsPcM13c7qZPWl3yyaVIYjI115jx2vLQyM6yqS/PSVkySla2RBH3cJkeUxkkLSPmtlEr+Atgv7XNm70Gv1W78fU3VSlMkWePPJSpV0LG+E4bnyCf9a4gUH5ts0/LMD8Cbv8TU/fzlDp5xDdmU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773070094; c=relaxed/simple; bh=y/mFYIyuOcug77wVmO/3w5D0nmPI/5VvLJP1Ns6W6+c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=avw7CB1Xk1CD0NstaOmk2z0saFNLy1YQiX8sEhdg/VjyGnelSpmLl3Qr+YomsJrjxcDnGH7h9JlM3QWjToRZV0AEQKjDrnjbaLMLollxRVNUtKsBbfT5g1DthiYz3ghzX7Do9aPbBGilmiy3u6JVeLORMiF7GSW0DUGt28LjaDE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=xrM//FP7; arc=none smtp.client-ip=185.246.85.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="xrM//FP7" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 74C724E425DC; Mon, 9 Mar 2026 15:28:12 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 497195FFB8; Mon, 9 Mar 2026 15:28:12 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id BFC1710369C01; Mon, 9 Mar 2026 16:28:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1773070090; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=qOb+0Lf49SHBvjUY22DDxptYUWGuVH23Ibz8ddjtz58=; b=xrM//FP7DtPzj1WRla8dHw5ZHP/ViqUanxDTQjp1ipA4zrqHSbOuD4Urr7KTfYCqxgtb+w c1LlyUv9WmmPMunB7kO6NEPBqYsnn5/GTFmhkNuqwj8ZuqeVXBsIe9dNIT9eCOlS9e12ac lnzoU97BibDWlgRwId+fsEHVNHgbe+i8Xg96Fbn18fJXI65B1XXGS1+x6GeXHEboiQh0/P ZgydptsGV55Zp78bnwxJ5gFnVfnTlMaFQfgV73/C5/JXcRJvC+DU5TIZH7Rb06fHS2EfMh j31rwzw07biPUO1siR6aDQt3u0dw7xDqBWo7q1KymbNNDFgRwdOOnnbtzabQfA== From: Maxime Chevallier To: davem@davemloft.net, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Russell King , Heiner Kallweit Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Christophe Leroy , Herve Codina , Florian Fainelli , Vladimir Oltean , =?UTF-8?q?K=C3=B6ry=20Maincent?= , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman , mwojtas@chromium.org, Romain Gantois , Daniel Golle , Dimitri Fedrau , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= Subject: [PATCH net-next v7 04/10] net: phy: Create SFP phy_port before registering upstream Date: Mon, 9 Mar 2026 16:27:40 +0100 Message-ID: <20260309152747.702373-5-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260309152747.702373-1-maxime.chevallier@bootlin.com> References: <20260309152747.702373-1-maxime.chevallier@bootlin.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 When dealing with PHY-driven SFP, we create a phy_port representing the SFP bus when we know we have such a bus. We can move the port creation before registering the sfp upstream ops, as long as we know the SFP bus is there. This will allow passing the phy_port along with the upstream information to the SFP bus. Signed-off-by: Maxime Chevallier --- drivers/net/phy/phy_device.c | 42 ++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 3bd415710bf3..152b5477e696 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1665,13 +1665,13 @@ static void phy_del_port(struct phy_device *phydev, struct phy_port *port) phydev->n_ports--; } -static int phy_setup_sfp_port(struct phy_device *phydev) +static struct phy_port *phy_setup_sfp_port(struct phy_device *phydev) { struct phy_port *port = phy_port_alloc(); int ret; if (!port) - return -ENOMEM; + return ERR_PTR(-ENOMEM); port->parent_type = PHY_PORT_PHY; port->phy = phydev; @@ -1686,10 +1686,12 @@ static int phy_setup_sfp_port(struct phy_device *phydev) * when attaching the port to the phydev. */ ret = phy_add_port(phydev, port); - if (ret) + if (ret) { phy_port_destroy(port); + return ERR_PTR(ret); + } - return ret; + return port; } /** @@ -1698,22 +1700,34 @@ static int phy_setup_sfp_port(struct phy_device *phydev) */ static int phy_sfp_probe(struct phy_device *phydev) { + struct phy_port *port = NULL; struct sfp_bus *bus; - int ret = 0; + int ret; - if (phydev->mdio.dev.fwnode) { - bus = sfp_bus_find_fwnode(phydev->mdio.dev.fwnode); - if (IS_ERR(bus)) - return PTR_ERR(bus); + if (!phydev->mdio.dev.fwnode) + return 0; + + bus = sfp_bus_find_fwnode(phydev->mdio.dev.fwnode); + if (IS_ERR(bus)) + return PTR_ERR(bus); - phydev->sfp_bus = bus; + phydev->sfp_bus = bus; - ret = sfp_bus_add_upstream(bus, phydev, &sfp_phydev_ops); - sfp_bus_put(bus); + if (bus) { + port = phy_setup_sfp_port(phydev); + if (IS_ERR(port)) { + sfp_bus_put(bus); + return PTR_ERR(port); + } } - if (!ret && phydev->sfp_bus) - ret = phy_setup_sfp_port(phydev); + ret = sfp_bus_add_upstream(bus, phydev, &sfp_phydev_ops); + sfp_bus_put(bus); + + if (ret && port) { + phy_del_port(phydev, port); + phy_port_destroy(port); + } return ret; } -- 2.49.0