From nobody Wed Dec 17 15:35:08 2025 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (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 3C54C14EC76; Tue, 7 May 2024 10:28:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715077711; cv=none; b=bRSmJEKcNlMEm/5qSKJ/pNdd1nI6KD7OuZ3Q3smy9wvYooKR4yVm0WV+wzpSYupZABNkqOBrLiSlCcqOFjN+23SqlqW9oggbyXQnJnrBV1dMZYtUQRHOVb+hxLS/RVFCNfEnJQ1sHOluuKW1j5eeZr/wxRCz1ft3MwBNbuyZbb8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715077711; c=relaxed/simple; bh=CRCJ3ykaVSd3ZnBKJHBvW/w+eALP52wdcUbDA3bJM9M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fG275MuV1ZiHG8ErkQRJ5BVhaK9V3ULTEB18UQvdWbguNBJ9+X1QtOgmec+KCLV3wpWiEjyxFO3kBYgczEbVSaOPPpWMlmgZJ8XbPCoZPV648AUC8FLmw9QEW4uUUAexzvqU7z6DLgBGsvincIulqicRBMhpwLGAmJWyBWTBQCk= 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=OlAq8jOo; arc=none smtp.client-ip=217.70.183.196 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="OlAq8jOo" Received: by mail.gandi.net (Postfix) with ESMTPSA id 29F12E0007; Tue, 7 May 2024 10:28:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1715077707; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AKWwksuY0e8vW4zcYVLDtjcgbFHAfKZqWORMINnwKqM=; b=OlAq8jOoJ75+I17s98OlHPmCCr9feqYy00e5yuFdxIyXcwxYITG6RhmUWC7CFkMjy7WnGO 3MFuz/wCfPl/jRuJMCIb80pdCBKKucqcsCG+FniG/FRtghfUzy5svditQh6x+Q2PrB/f6o f/kWJwN/IvAY3rxCRNlLIP7W8PseU5HOB7CVyPXVD7r3dfwrR/ipCTWiE+F9JfCQLNzMrB /1Qy6DxphY0YhvLgISzRzEwSQ+m1/vERXBbZzfo1RBl3Ysl/HDwp8J40DCPRvVtvFk/4cV A168qZxKZi51Ua6o5WxlltSPMZ4QtKAdOvj9DvH7GIpsLIdgrhleUGJs9fWA5g== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Russell King , linux-arm-kernel@lists.infradead.org, Christophe Leroy , Herve Codina , Florian Fainelli , Heiner Kallweit , Vladimir Oltean , =?UTF-8?q?K=C3=B6ry=20Maincent?= , Jesse Brandeburg , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Piergiorgio Beruto , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman , mwojtas@chromium.org, Nathan Chancellor , Antoine Tenart Subject: [PATCH net-next 1/2] net: phy: phy_link_topology: Pass netdevice to phy_link_topo helpers Date: Tue, 7 May 2024 12:28:20 +0200 Message-ID: <20240507102822.2023826-2-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240507102822.2023826-1-maxime.chevallier@bootlin.com> References: <20240507102822.2023826-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-GND-Sasl: maxime.chevallier@bootlin.com Content-Type: text/plain; charset="utf-8" The phy link topology's main goal is to better track which PHYs are connected to a given netdevice. Make so that the helpers take the netdevice as a parameter directly. Signed-off-by: Maxime Chevallier Fixes: 6916e461e793 ("net: phy: Introduce ethernet link topology representa= tion") Closes: https://lore.kernel.org/netdev/2e11b89d-100f-49e7-9c9a-834cc0b82f97= @gmail.com/ Closes: https://lore.kernel.org/netdev/20240409201553.GA4124869@dev-arch.th= elio-3990X/ --- drivers/net/phy/phy_device.c | 25 ++++++++----------------- drivers/net/phy/phy_link_topology.c | 13 ++++++++++--- include/linux/phy_link_topology.h | 21 +++++++++++++-------- net/ethtool/netlink.c | 2 +- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 616bd7ba46cb..111434201545 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -277,14 +277,6 @@ static void phy_mdio_device_remove(struct mdio_device = *mdiodev) =20 static struct phy_driver genphy_driver; =20 -static struct phy_link_topology *phy_get_link_topology(struct phy_device *= phydev) -{ - if (phydev->attached_dev) - return phydev->attached_dev->link_topo; - - return NULL; -} - static LIST_HEAD(phy_fixup_list); static DEFINE_MUTEX(phy_fixup_lock); =20 @@ -1389,10 +1381,10 @@ static DEVICE_ATTR_RO(phy_standalone); int phy_sfp_connect_phy(void *upstream, struct phy_device *phy) { struct phy_device *phydev =3D upstream; - struct phy_link_topology *topo =3D phy_get_link_topology(phydev); + struct net_device *dev =3D phydev->attached_dev; =20 - if (topo) - return phy_link_topo_add_phy(topo, phy, PHY_UPSTREAM_PHY, phydev); + if (dev) + return phy_link_topo_add_phy(dev, phy, PHY_UPSTREAM_PHY, phydev); =20 return 0; } @@ -1411,10 +1403,10 @@ EXPORT_SYMBOL(phy_sfp_connect_phy); void phy_sfp_disconnect_phy(void *upstream, struct phy_device *phy) { struct phy_device *phydev =3D upstream; - struct phy_link_topology *topo =3D phy_get_link_topology(phydev); + struct net_device *dev =3D phydev->attached_dev; =20 - if (topo) - phy_link_topo_del_phy(topo, phy); + if (dev) + phy_link_topo_del_phy(dev, phy); } EXPORT_SYMBOL(phy_sfp_disconnect_phy); =20 @@ -1561,8 +1553,7 @@ int phy_attach_direct(struct net_device *dev, struct = phy_device *phydev, if (phydev->sfp_bus_attached) dev->sfp_bus =3D phydev->sfp_bus; =20 - err =3D phy_link_topo_add_phy(dev->link_topo, phydev, - PHY_UPSTREAM_MAC, dev); + err =3D phy_link_topo_add_phy(dev, phydev, PHY_UPSTREAM_MAC, dev); if (err) goto error; } @@ -1992,7 +1983,7 @@ void phy_detach(struct phy_device *phydev) if (dev) { phydev->attached_dev->phydev =3D NULL; phydev->attached_dev =3D NULL; - phy_link_topo_del_phy(dev->link_topo, phydev); + phy_link_topo_del_phy(dev, phydev); } phydev->phylink =3D NULL; =20 diff --git a/drivers/net/phy/phy_link_topology.c b/drivers/net/phy/phy_link= _topology.c index 985941c5c558..0e36bd7c15dc 100644 --- a/drivers/net/phy/phy_link_topology.c +++ b/drivers/net/phy/phy_link_topology.c @@ -35,10 +35,11 @@ void phy_link_topo_destroy(struct phy_link_topology *to= po) kfree(topo); } =20 -int phy_link_topo_add_phy(struct phy_link_topology *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_device_node *pdn; int ret; =20 @@ -90,10 +91,16 @@ int phy_link_topo_add_phy(struct phy_link_topology *top= o, } EXPORT_SYMBOL_GPL(phy_link_topo_add_phy); =20 -void phy_link_topo_del_phy(struct phy_link_topology *topo, +void phy_link_topo_del_phy(struct net_device *dev, struct phy_device *phy) { - struct phy_device_node *pdn =3D xa_erase(&topo->phys, phy->phyindex); + struct phy_link_topology *topo =3D dev->link_topo; + struct phy_device_node *pdn; + + if (!topo) + return; + + pdn =3D xa_erase(&topo->phys, phy->phyindex); =20 /* We delete the PHY from the topology, however we don't re-set the * phy->phyindex field. If the PHY isn't gone, we can re-assign it the diff --git a/include/linux/phy_link_topology.h b/include/linux/phy_link_top= ology.h index 6b79feb607e7..166a01710aa2 100644 --- a/include/linux/phy_link_topology.h +++ b/include/linux/phy_link_topology.h @@ -12,11 +12,11 @@ #define __PHY_LINK_TOPOLOGY_H =20 #include +#include #include =20 struct xarray; struct phy_device; -struct net_device; struct sfp_bus; =20 struct phy_device_node { @@ -37,11 +37,16 @@ struct phy_link_topology { u32 next_phy_index; }; =20 -static inline struct phy_device * -phy_link_topo_get_phy(struct phy_link_topology *topo, u32 phyindex) +static inline struct phy_device +*phy_link_topo_get_phy(struct net_device *dev, u32 phyindex) { - struct phy_device_node *pdn =3D xa_load(&topo->phys, phyindex); + struct phy_link_topology *topo =3D dev->link_topo; + struct phy_device_node *pdn; =20 + if (!topo) + return NULL; + + pdn =3D xa_load(&topo->phys, phyindex); if (pdn) return pdn->phy; =20 @@ -49,21 +54,21 @@ phy_link_topo_get_phy(struct phy_link_topology *topo, u= 32 phyindex) } =20 #if IS_REACHABLE(CONFIG_PHYLIB) -int phy_link_topo_add_phy(struct phy_link_topology *topo, +int phy_link_topo_add_phy(struct net_device *dev, struct phy_device *phy, enum phy_upstream upt, void *upstream); =20 -void phy_link_topo_del_phy(struct phy_link_topology *lt, struct phy_device= *phy); +void phy_link_topo_del_phy(struct net_device *dev, struct phy_device *phy); =20 #else -static inline int phy_link_topo_add_phy(struct phy_link_topology *topo, +static inline int phy_link_topo_add_phy(struct net_device *dev, struct phy_device *phy, enum phy_upstream upt, void *upstream) { return 0; } =20 -static inline void phy_link_topo_del_phy(struct phy_link_topology *topo, +static inline void phy_link_topo_del_phy(struct net_device *dev, struct phy_device *phy) { } diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index 563e94e0cbd8..f5b4adf324bc 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -170,7 +170,7 @@ int ethnl_parse_header_dev_get(struct ethnl_req_info *r= eq_info, struct nlattr *phy_id; =20 phy_id =3D tb[ETHTOOL_A_HEADER_PHY_INDEX]; - phydev =3D phy_link_topo_get_phy(dev->link_topo, + phydev =3D phy_link_topo_get_phy(dev, nla_get_u32(phy_id)); if (!phydev) { NL_SET_BAD_ATTR(extack, phy_id); --=20 2.44.0 From nobody Wed Dec 17 15:35:08 2025 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (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 85EFE14F9C3; Tue, 7 May 2024 10:28:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715077714; cv=none; b=bGuxsIP6ZH5dt8sNeCw5XQTR7RdLoycs0DS7OYkFqthGK6gYCDdaAO710eLRendZamS5NT4/x0oJcMvUnHxI7Z/avF47TDQJL/0EiZguTaYsD3g4Dbj8gUEheScJpyzxir3OKHYlR8Pwi8uWJJVLGN1KVvX7B8mrleBxTrQCwCo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715077714; c=relaxed/simple; bh=EirpOcfHbhxzX5mT3leqr6K3yZqEuE5UCC8AzPDkzgU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N2eB7VvOCuizChOH2rk107+YScpip37asmF4aYkW99ut66Ic9n+0y+qCDpZNxIFYSGP00ucvB/zvjdHuOplhT1sOoodCjqWDohRoB3M6BYLcxiAiXMuwaDoFarW7NiTIWglyhLODu2MOfH6IO77mivRvDwYLqF2AEgMfsBnOGuE= 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=mAfcNcwr; arc=none smtp.client-ip=217.70.183.196 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="mAfcNcwr" Received: by mail.gandi.net (Postfix) with ESMTPSA id 8B99FE0004; Tue, 7 May 2024 10:28:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1715077708; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CUadJuWaqhi+XpEWHDh3AN7U2iQoAUeidf5WQOmYOpA=; b=mAfcNcwrAZRpbUmnaGm2ZWNEFMXcdCee0YfFjU6W8xu/Exp+ggJzi20dNqMt7Evgd06mj3 baEHbfAoNkQK8mxvgTmq0K7eFYGGDz4JWW2n9KYKGrWVhF90is/Iaib04gUAZfFfJIJCwf I1KIF7xUou9i3pMTJuSOKtrc6YYXYbh4E3yap5RU8lk0hII/+prnIiebvoG6gTifDrYSzL 8IntoFByLa0syCQkmkAZZyZ0XIiVtg4xayRWDOkU5YrIDn6gVSVzlyfveD4g70OaPevL31 +YlxiI9RSDe18/eiLxHkkJM/rGhpBw7Ah1gSapSQHndvUqOhfFiGUl3BuBE+Cw== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Russell King , linux-arm-kernel@lists.infradead.org, Christophe Leroy , Herve Codina , Florian Fainelli , Heiner Kallweit , Vladimir Oltean , =?UTF-8?q?K=C3=B6ry=20Maincent?= , Jesse Brandeburg , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Piergiorgio Beruto , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman , mwojtas@chromium.org, Nathan Chancellor , Antoine Tenart Subject: [PATCH net-next 2/2] net: phy: phy_link_topology: Lazy-initialize the link topology Date: Tue, 7 May 2024 12:28:21 +0200 Message-ID: <20240507102822.2023826-3-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240507102822.2023826-1-maxime.chevallier@bootlin.com> References: <20240507102822.2023826-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-GND-Sasl: maxime.chevallier@bootlin.com Content-Type: text/plain; charset="utf-8" Having the net_device's init path for the link_topology depend on IS_REACHABLE(PHYLIB)-protected helpers triggers errors when modules are bei= ng built with phylib as a module as-well, as they expect netdev->link_topo to be initialized. Move the link_topo initialization at the first PHY insertion, which will both improve the memory usage, and make the behaviour more predicatble and robust. Signed-off-by: Maxime Chevallier Fixes: 6916e461e793 ("net: phy: Introduce ethernet link topology representa= tion") Closes: https://lore.kernel.org/netdev/2e11b89d-100f-49e7-9c9a-834cc0b82f97= @gmail.com/ Closes: https://lore.kernel.org/netdev/20240409201553.GA4124869@dev-arch.th= elio-3990X/ --- drivers/net/phy/phy_link_topology.c | 31 ++++++--------------- include/linux/netdevice.h | 2 ++ include/linux/phy_link_topology.h | 23 ++++++++-------- include/linux/phy_link_topology_core.h | 23 +++------------- net/core/dev.c | 38 ++++++++++++++++++++++---- 5 files changed, 58 insertions(+), 59 deletions(-) diff --git a/drivers/net/phy/phy_link_topology.c b/drivers/net/phy/phy_link= _topology.c index 0e36bd7c15dc..b1aba9313e73 100644 --- a/drivers/net/phy/phy_link_topology.c +++ b/drivers/net/phy/phy_link_topology.c @@ -12,29 +12,6 @@ #include #include =20 -struct phy_link_topology *phy_link_topo_create(struct net_device *dev) -{ - struct phy_link_topology *topo; - - topo =3D kzalloc(sizeof(*topo), GFP_KERNEL); - if (!topo) - return ERR_PTR(-ENOMEM); - - xa_init_flags(&topo->phys, XA_FLAGS_ALLOC1); - topo->next_phy_index =3D 1; - - return topo; -} - -void phy_link_topo_destroy(struct phy_link_topology *topo) -{ - if (!topo) - return; - - xa_destroy(&topo->phys); - kfree(topo); -} - int phy_link_topo_add_phy(struct net_device *dev, struct phy_device *phy, enum phy_upstream upt, void *upstream) @@ -43,6 +20,14 @@ int phy_link_topo_add_phy(struct net_device *dev, 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; + } + pdn =3D kzalloc(sizeof(*pdn), GFP_KERNEL); if (!pdn) return -ENOMEM; diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index cf261fb89d73..25a0a77cfadc 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -4569,6 +4569,8 @@ void __hw_addr_unsync_dev(struct netdev_hw_addr_list = *list, const unsigned char *)); void __hw_addr_init(struct netdev_hw_addr_list *list); =20 +int netdev_alloc_phy_link_topology(struct net_device *dev); + /* Functions used for device addresses handling */ void dev_addr_mod(struct net_device *dev, unsigned int offset, const void *addr, size_t len); diff --git a/include/linux/phy_link_topology.h b/include/linux/phy_link_top= ology.h index 166a01710aa2..3501f9a9e932 100644 --- a/include/linux/phy_link_topology.h +++ b/include/linux/phy_link_topology.h @@ -32,10 +32,12 @@ struct phy_device_node { struct phy_device *phy; }; =20 -struct phy_link_topology { - struct xarray phys; - u32 next_phy_index; -}; +#if IS_ENABLED(CONFIG_PHYLIB) +int phy_link_topo_add_phy(struct net_device *dev, + struct phy_device *phy, + enum phy_upstream upt, void *upstream); + +void phy_link_topo_del_phy(struct net_device *dev, struct phy_device *phy); =20 static inline struct phy_device *phy_link_topo_get_phy(struct net_device *dev, u32 phyindex) @@ -53,13 +55,6 @@ static inline struct phy_device return NULL; } =20 -#if IS_REACHABLE(CONFIG_PHYLIB) -int phy_link_topo_add_phy(struct net_device *dev, - struct phy_device *phy, - enum phy_upstream upt, void *upstream); - -void phy_link_topo_del_phy(struct net_device *dev, struct phy_device *phy); - #else static inline int phy_link_topo_add_phy(struct net_device *dev, struct phy_device *phy, @@ -72,6 +67,12 @@ static inline void phy_link_topo_del_phy(struct net_devi= ce *dev, struct phy_device *phy) { } + +static inline struct phy_device * +phy_link_topo_get_phy(struct net_device *dev, u32 phyindex) +{ + return NULL; +} #endif =20 #endif /* __PHY_LINK_TOPOLOGY_H */ diff --git a/include/linux/phy_link_topology_core.h b/include/linux/phy_lin= k_topology_core.h index 0a6479055745..f9c0520806fb 100644 --- a/include/linux/phy_link_topology_core.h +++ b/include/linux/phy_link_topology_core.h @@ -2,24 +2,9 @@ #ifndef __PHY_LINK_TOPOLOGY_CORE_H #define __PHY_LINK_TOPOLOGY_CORE_H =20 -struct phy_link_topology; - -#if IS_REACHABLE(CONFIG_PHYLIB) - -struct phy_link_topology *phy_link_topo_create(struct net_device *dev); -void phy_link_topo_destroy(struct phy_link_topology *topo); - -#else - -static inline struct phy_link_topology *phy_link_topo_create(struct net_de= vice *dev) -{ - return NULL; -} - -static inline void phy_link_topo_destroy(struct phy_link_topology *topo) -{ -} - -#endif +struct phy_link_topology { + struct xarray phys; + u32 next_phy_index; +}; =20 #endif /* __PHY_LINK_TOPOLOGY_CORE_H */ diff --git a/net/core/dev.c b/net/core/dev.c index d2ce91a334c1..1b4ffc273a04 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10256,6 +10256,35 @@ static void netdev_do_free_pcpu_stats(struct net_d= evice *dev) } } =20 +int netdev_alloc_phy_link_topology(struct net_device *dev) +{ + struct phy_link_topology *topo; + + topo =3D kzalloc(sizeof(*topo), GFP_KERNEL); + if (!topo) + return -ENOMEM; + + xa_init_flags(&topo->phys, XA_FLAGS_ALLOC1); + topo->next_phy_index =3D 1; + + dev->link_topo =3D topo; + + return 0; +} +EXPORT_SYMBOL_GPL(netdev_alloc_phy_link_topology); + +static void netdev_free_phy_link_topology(struct net_device *dev) +{ + struct phy_link_topology *topo =3D dev->link_topo; + + if (!topo) + return; + + xa_destroy(&topo->phys); + kfree(topo); + dev->link_topo =3D NULL; +} + /** * register_netdevice() - register a network device * @dev: device to register @@ -10998,11 +11027,6 @@ struct net_device *alloc_netdev_mqs(int sizeof_pri= v, const char *name, #ifdef CONFIG_NET_SCHED hash_init(dev->qdisc_hash); #endif - dev->link_topo =3D phy_link_topo_create(dev); - if (IS_ERR(dev->link_topo)) { - dev->link_topo =3D NULL; - goto free_all; - } =20 dev->priv_flags =3D IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM; setup(dev); @@ -11092,7 +11116,9 @@ void free_netdev(struct net_device *dev) free_percpu(dev->xdp_bulkq); dev->xdp_bulkq =3D NULL; =20 - phy_link_topo_destroy(dev->link_topo); +#if IS_ENABLED(CONFIG_PHYLIB) + netdev_free_phy_link_topology(dev); +#endif =20 /* Compatibility with error handling in drivers */ if (dev->reg_state =3D=3D NETREG_UNINITIALIZED || --=20 2.44.0