From nobody Sun Feb 8 16:31:11 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (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 6ECEA1FFC59; Sun, 1 Feb 2026 15:13:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769958798; cv=none; b=Pkvdn2z6dndJLNvZyb2/czzxE476sZSBYV0K7xka61obxi2i7z4m+99XyZ4kbvpFUYyokRZhTSkHfgP3LlV9Io1l3L/rNrKvXv5+96M7A9QUqTpVHhuXorv2LngVA2imntTK8yXc5bHMI+Nwr83zkD0AqzfNvBb74KjO6pf3f+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769958798; c=relaxed/simple; bh=FzfPssaMTtMlTXsQB3uWK2d1KPWw1AhO9CiOrY0mA4o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nCV7ERZc13bELED4Rlm5qHHUyvc1U/yj1aazG22Z7idovRXmMlJgKJjQooUS7M1PBDqLjClzDSTztbTPjAlknUq7DXGb1Rc7ALkpqz8pyBMtushnZ3Xt8GWQGiTrvLhoTdPfNlr3sBHEOiz8BKiPtiWFdBJfhclyHthNKJHzYBs= 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=imELCQ3R; arc=none smtp.client-ip=185.246.84.56 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="imELCQ3R" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id D0CD81A2B85; Sun, 1 Feb 2026 15:13:13 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id A451660720; Sun, 1 Feb 2026 15:13:13 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 9FC20119A88F3; Sun, 1 Feb 2026 16:13:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1769958792; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=LWzrt0LzFGZIeHx1tJakp6EzeCmz9kccT2ixoT2csH8=; b=imELCQ3RELrr2DQTcAMGq7IAhvvo+F4ckXfGsg5NUwX2XMNYs0lGYL8DIyDcwzvDYt2XqL gFr4IoI1AS24KLmpro2cLH7VQxGblzgGQFlFyAlYy7VnsiYIU7BsxPuMpbSfsEH6g3wMSb D3kTjolvkbTeY67Gb3Egt4i0hyGvxVdmEaZrAcCb+qyzF+lHCspvqwYSFfTlDihm8hYWlR PLvRcxgIszqoHikA/z2PeIcXrMoEz3RsZBcn/ELSmf4c4UXXVSG3Yo3uBijnJypmwgjGMj tjhdlMSSm9U+0O2CT2TItOM0Ydj7kdtkH2kXFh3EXTxxqIMeYVfRaSAZwyfdZw== 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 v3 02/11] net: phy: phy_link_topology: Add a helper for opportunistic alloc Date: Sun, 1 Feb 2026 16:12:39 +0100 Message-ID: <20260201151249.642015-3-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260201151249.642015-1-maxime.chevallier@bootlin.com> References: <20260201151249.642015-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" The phy_link_topology structure stores information about the PHY-related components connected to a net_device. It is opportunistically allocated, when we add the first item to the topology, as this is not relevant for all kinds of net_devices. In preparation for the addition of phy_port tracking in the topology, let's make a dedicated helper for that allocation sequence. Signed-off-by: Maxime Chevallier --- drivers/net/phy/phy_link_topology.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/net/phy/phy_link_topology.c b/drivers/net/phy/phy_link= _topology.c index 0e9e987f37dd..7dc2ff10c74a 100644 --- a/drivers/net/phy/phy_link_topology.c +++ b/drivers/net/phy/phy_link_topology.c @@ -27,21 +27,34 @@ static int netdev_alloc_phy_link_topology(struct net_de= vice *dev) return 0; } =20 +static struct phy_link_topology *phy_link_topo_get_or_alloc(struct net_dev= ice *dev) +{ + int ret; + + if (dev->link_topo) + return dev->link_topo; + + /* The topology is allocated the first time we add an object to it. + * It is freed alongside the netdev. + */ + ret =3D netdev_alloc_phy_link_topology(dev); + if (ret) + return ERR_PTR(ret); + + return dev->link_topo; +} + int phy_link_topo_add_phy(struct net_device *dev, struct phy_device *phy, enum phy_upstream upt, void *upstream) { - struct phy_link_topology *topo =3D dev->link_topo; + struct phy_link_topology *topo; struct phy_device_node *pdn; int ret; =20 - if (!topo) { - ret =3D netdev_alloc_phy_link_topology(dev); - if (ret) - return ret; - - topo =3D dev->link_topo; - } + topo =3D phy_link_topo_get_or_alloc(dev); + if (IS_ERR(topo)) + return PTR_ERR(topo); =20 pdn =3D kzalloc(sizeof(*pdn), GFP_KERNEL); if (!pdn) --=20 2.49.0