Re: [net-next,v2,03/12] net: phy: phy_link_topology: Track ports in phy_link_topology

From: Jakub Kicinski

Date: Thu Jan 29 2026 - 23:01:35 EST


This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.

For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
net: phy: phy_link_topology: Track ports in phy_link_topology

This commit adds a new ports xarray to phy_link_topology to track
phy_port structures alongside PHY devices. The ports are added when
a PHY is added and removed when a PHY is removed.

> diff --git a/drivers/net/phy/phy_link_topology.c b/drivers/net/phy/phy_link_topology.c
> index 7dc2ff10c74a..456f1144e83e 100644
> --- a/drivers/net/phy/phy_link_topology.c
> +++ b/drivers/net/phy/phy_link_topology.c

[ ... ]

> @@ -22,6 +23,9 @@ static int netdev_alloc_phy_link_topology(struct net_device *dev)
> xa_init_flags(&topo->phys, XA_FLAGS_ALLOC1);
> topo->next_phy_index = 1;
>
> + xa_init_flags(&topo->ports, XA_FLAGS_ALLOC1);
> + topo->next_port_index = 1;
> +
> dev->link_topo = topo;
>
> return 0;

The ports xarray is initialized here, but netdev_free_phy_link_topology()
in net/core/dev.c only calls xa_destroy() on topo->phys:

static void netdev_free_phy_link_topology(struct net_device *dev)
{
struct phy_link_topology *topo = dev->link_topo;

if (IS_ENABLED(CONFIG_PHYLIB) && topo) {
xa_destroy(&topo->phys);
kfree(topo);
dev->link_topo = NULL;
}
}

Should xa_destroy(&topo->ports) be added before the kfree(topo) to avoid
leaking memory allocated by the ports xarray?