From nobody Mon Feb 9 11:47:29 2026 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 C6F2E3D5249; Tue, 3 Feb 2026 17:29:11 +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=1770139753; cv=none; b=ZcoOdL5/WqDJ1+4f0hVP/PqN6y1Rth5oRF+8yPBa2MZE06bL4TO6jS8HIACRWGV5v94TjnPB/82slauBTS1V2Ggwo7t/RI+yjXKjg5GphkpV0hPWV/ETLAtpe1T1HWd+8d5frF3zAMKNBXG7C5fkVMjeAaB4D3z08r1nxT9nWDY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770139753; c=relaxed/simple; bh=cMWmsJsTCCclDJN4POGmYUlnnYV29W+lsKydlQUZvEc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qfZ6AbpWoUxVUtWxKoi6I5O/2EE9mTZ/veyjMvr/ATTEg2ctsB+thGyMB6E1AtyTt0IvnGmJ5r63tU+VsfvTTV/VmBThFvCr8XmTgOIiBLUbIVb4sxGSQrQ7m6smwu+Un12RZAjziYZHSV1Y7siKgebjQ0sYxYnpqApqWIVClrU= 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=jmcCuCPI; 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="jmcCuCPI" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 6E5B14E423E7; Tue, 3 Feb 2026 17:29:10 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 3FD5060728; Tue, 3 Feb 2026 17:29:10 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id E4D9A119A88F7; Tue, 3 Feb 2026 18:29:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1770139749; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=lcFBegye7Q2h6C5rnPUpxufhF5WGGgfujHXqDQjkhIY=; b=jmcCuCPIjY/ml5i5EW1HFkrRRGIET8pqjx5NVsP+Jg0zJyHwrwbiwrbJzXxf+jGjkAVGct tpXdxvqWDaE3lruA/ptw3x9ZS5RUTMTfwoSDwwwBfQGxkVMY34VNpHINN1U+3HcO2RW145 Rzts+MACbaYnueFH1D0scshBJoap/eK5t8XMI4/D8hldIBqjYTEGYSLZsw9FkCshdKPHNs wLjpOe3riXmP9GZX9SS9+pDNU0Jl1RGiu2Y7cKsv1ZA1HoGVia7hMC54+3l44UpNAuV2Tq N+tdQSbSoUEUINpy4qhQqr1oCeFKqDFGgoWu4Z87XBOeVV/1jzLjua+hm8ErYA== 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 Subject: [PATCH net-next v4 07/13] net: phy: Create SFP phy_port before registering upstream Date: Tue, 3 Feb 2026 18:28:31 +0100 Message-ID: <20260203172839.548524-8-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260203172839.548524-1-maxime.chevallier@bootlin.com> References: <20260203172839.548524-1-maxime.chevallier@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" 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 9b8eaac63b90..b0971f57686c 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--; } =20 -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 =3D phy_port_alloc(); int ret; =20 if (!port) - return -ENOMEM; + return ERR_PTR(-ENOMEM); =20 port->parent_type =3D PHY_PORT_PHY; port->phy =3D phydev; @@ -1686,10 +1686,12 @@ static int phy_setup_sfp_port(struct phy_device *ph= ydev) * when attaching the port to the phydev. */ ret =3D phy_add_port(phydev, port); - if (ret) + if (ret) { phy_port_destroy(port); + return ERR_PTR(ret); + } =20 - return ret; + return port; } =20 /** @@ -1698,22 +1700,34 @@ static int phy_setup_sfp_port(struct phy_device *ph= ydev) */ static int phy_sfp_probe(struct phy_device *phydev) { + struct phy_port *port; struct sfp_bus *bus; - int ret =3D 0; + int ret; =20 - if (phydev->mdio.dev.fwnode) { - bus =3D sfp_bus_find_fwnode(phydev->mdio.dev.fwnode); - if (IS_ERR(bus)) - return PTR_ERR(bus); + if (!phydev->mdio.dev.fwnode) + return 0; + + bus =3D sfp_bus_find_fwnode(phydev->mdio.dev.fwnode); + if (IS_ERR(bus)) + return PTR_ERR(bus); =20 - phydev->sfp_bus =3D bus; + phydev->sfp_bus =3D bus; =20 - ret =3D sfp_bus_add_upstream(bus, phydev, &sfp_phydev_ops); - sfp_bus_put(bus); + if (bus) { + port =3D phy_setup_sfp_port(phydev); + if (IS_ERR(port)) { + sfp_bus_put(bus); + return PTR_ERR(port); + } } =20 - if (!ret && phydev->sfp_bus) - ret =3D phy_setup_sfp_port(phydev); + ret =3D 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); + } =20 return ret; } --=20 2.49.0