From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (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 A4A333B530F for ; Wed, 4 Mar 2026 14:54:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772636101; cv=none; b=GnayN+gT/yJspZNIjSLCPt+F+Y8dqW7rXPfCa4Al510O8F4U3Wlf4L8RxboOZhjWITkz2KZzvlk3+KbjYOs0MLuiDSKvKbGf7tPxyKfhrH5ylicmrBM7l/+KzgSPL8WouI0v3OfVoeEkI0SBKTXwX/bcIGxGoCzRjSJz8L1E/7c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772636101; c=relaxed/simple; bh=Wsz2AZSfO3CMZ9hi9RAex30t9IvMTQzL9FzkNmtSFG8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LOkXo333K8hYI+Sv9C9ClTNw+rBm+s0x3su2vZ1MoFMHC5fyDiaAlgbcj+PEqae88icWuwnITnLulDqIdbOhFK/Vy1bg9ewxuK19yRVUbAN6p8r3ZUBE8tVy8pdDAgykEaQNp+wReW8xsC6pXTQxLEismN3Rgi8d2anlWd97Bww= 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=pC7VQrd2; arc=none smtp.client-ip=185.171.202.116 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="pC7VQrd2" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id F32F1C143FC; Wed, 4 Mar 2026 14:55:15 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id CDC335FF5C; Wed, 4 Mar 2026 14:54:57 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id D02BD102F17D7; Wed, 4 Mar 2026 15:54:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1772636096; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=AR1POQwTIVmZIlP545WnmjBu2iS3sERk3rgCHJfHWpA=; b=pC7VQrd2mncFXiAgMH5202yLRNhyFnOkY+ei0sNKHu2/8POCc7sDQ6L8kLAvjQbl+0F/1k XOgBPTrrgbc+A5mGq5hg/19FBNYLhEuPN/dAjyHMNPFTG4fnH34tC6QirmpHsDr/g6zGn/ 0Y+PdyPVIstjI16Vd4L07Uog9OEzYBtSND8qXIXuyB6hybU3c/0xx1uaUgS/QixrDBFOu7 /7nG5zZKRqgIhM5pdC8fIpW7UxG6JIKs81ATVQOE6dGrSojTgKvkqDF3u1vNfqjk5O54DW 2PctnYMtJo8l7Y5vi3ykqjJm3MHWDiPcdWa+K35vymeEJQqux87hFc8oD5wN8g== 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 v6 01/10] net: phy: phy_link_topology: Add a helper for opportunistic alloc Date: Wed, 4 Mar 2026 15:54:32 +0100 Message-ID: <20260304145444.442334-2-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260304145444.442334-1-maxime.chevallier@bootlin.com> References: <20260304145444.442334-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 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 1f1eb5d59b38..fdfafd951905 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_device *dev) return 0; } +static struct phy_link_topology *phy_link_topo_get_or_alloc(struct net_device *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 = 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 = dev->link_topo; + struct phy_link_topology *topo; struct phy_device_node *pdn; int ret; - if (!topo) { - ret = netdev_alloc_phy_link_topology(dev); - if (ret) - return ret; - - topo = dev->link_topo; - } + topo = phy_link_topo_get_or_alloc(dev); + if (IS_ERR(topo)) + return PTR_ERR(topo); pdn = kzalloc_obj(*pdn); if (!pdn) -- 2.49.0