From: Simon Horman <horms@kernel.org>
To: maxime.chevallier@bootlin.com
Cc: Simon Horman <horms@kernel.org>,
vladimir.oltean@nxp.com, andrew@lunn.ch, pabeni@redhat.com,
linux-kernel@vger.kernel.org, hkallweit1@gmail.com,
kory.maincent@bootlin.com, davem@davemloft.net,
romain.gantois@bootlin.com, edumazet@google.com,
daniel@makrotopia.org, herve.codina@bootlin.com,
nicveronese@gmail.com, kuba@kernel.org, kabel@kernel.org,
dimitri.fedrau@liebherr.com, christophe.leroy@csgroup.eu,
f.fainelli@gmail.com, linux@armlinux.org.uk,
netdev@vger.kernel.org, mwojtas@chromium.org,
thomas.petazzoni@bootlin.com, o.rempel@pengutronix.de
Subject: Re: [net-next,v6,02/10] net: phy: phy_link_topology: Track ports in phy_link_topology
Date: Fri, 6 Mar 2026 14:09:11 +0000 [thread overview]
Message-ID: <20260306140911.495181-1-horms@kernel.org> (raw)
In-Reply-To: <20260304145444.442334-3-maxime.chevallier@bootlin.com>
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 port tracking to phy_link_topology by introducing a
ports xarray alongside the existing phys xarray. PHY-driven ports are
registered and tracked with unique IDs that can be reused.
> diff --git a/drivers/net/phy/phy_link_topology.c b/drivers/net/phy/phy_link_topology.c
> index fdfafd951905..f7946c73dc5f 100644
> --- a/drivers/net/phy/phy_link_topology.c
> +++ b/drivers/net/phy/phy_link_topology.c
[ ... ]
> @@ -89,8 +126,20 @@ int phy_link_topo_add_phy(struct net_device *dev,
> if (ret < 0)
> goto err;
>
> + /* Add all the PHY's ports to the topology */
> + list_for_each_entry(port, &phy->ports, head) {
> + ret = phy_link_topo_add_port(dev, port);
> + if (ret)
> + goto del_ports;
> + }
> +
> return 0;
>
> +del_ports:
> + list_for_each_entry_from_reverse(port, &phy->ports, head)
> + phy_link_topo_del_port(dev, port);
Does this rollback sequence incorrectly delete a port that was never added?
list_for_each_entry_from_reverse() starts at the current entry (the port
that FAILED to add) and iterates backward. This means phy_link_topo_del_port()
is called on the failed port that was never successfully added to the xarray.
Looking at phy_link_topo_del_port():
void phy_link_topo_del_port(struct net_device *dev, struct phy_port *port)
{
struct phy_link_topology *topo = dev->link_topo;
if (!topo)
return;
xa_erase(&topo->ports, port->id);
}
The spurious xa_erase() is likely harmless in the -ENOMEM case from
xa_alloc_cyclic with port->id == 0, because XA_FLAGS_ALLOC1 reserves index 0.
However, in the xa_insert -EBUSY failure case where port->id is non-zero
and the slot is occupied by a different port, the rollback incorrectly
erases the other port's xarray entry, causing silent data corruption in
the topology's port tracking.
Should this use list_for_each_entry_continue_reverse() instead? That macro
starts from the entry BEFORE the current position, skipping the failed port
and only rolling back successfully-added ports.
The existing xa_alloc_cyclic error handling in the same function uses
'if (ret < 0) goto err' which correctly skips the failed PHY in cleanup.
> +
> + xa_erase(&topo->phys, phy->phyindex);
> err:
> kfree(pdn);
> return ret;
[ ... ]
next prev parent reply other threads:[~2026-03-06 14:09 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-04 14:54 [PATCH net-next v6 00/10] net: phy_port: SFP modules representation and phy_port listing Maxime Chevallier
2026-03-04 14:54 ` [PATCH net-next v6 01/10] net: phy: phy_link_topology: Add a helper for opportunistic alloc Maxime Chevallier
2026-03-04 14:54 ` [PATCH net-next v6 02/10] net: phy: phy_link_topology: Track ports in phy_link_topology Maxime Chevallier
2026-03-06 14:09 ` Simon Horman [this message]
2026-03-06 15:57 ` [net-next,v6,02/10] " Maxime Chevallier
2026-03-04 14:54 ` [PATCH net-next v6 03/10] net: phylink: Register a phy_port for MAC-driven SFP busses Maxime Chevallier
2026-03-04 14:54 ` [PATCH net-next v6 04/10] net: phy: Create SFP phy_port before registering upstream Maxime Chevallier
2026-03-04 14:54 ` [PATCH net-next v6 05/10] net: phy: Represent PHY-less SFP modules with phy_port Maxime Chevallier
2026-03-04 14:54 ` [PATCH net-next v6 06/10] net: phylink: " Maxime Chevallier
2026-03-04 14:54 ` [PATCH net-next v6 07/10] net: phy: phy_port: Store information about a MII port's vacant state Maxime Chevallier
2026-03-06 14:03 ` [net-next,v6,07/10] " Simon Horman
2026-03-06 15:50 ` Maxime Chevallier
2026-03-04 14:54 ` [PATCH net-next v6 08/10] net: phy: phy_link_topology: Add a helper to retrieve ports Maxime Chevallier
2026-03-04 14:54 ` [PATCH net-next v6 09/10] netlink: specs: Add ethernet port listing with ethtool Maxime Chevallier
2026-03-04 14:54 ` [PATCH net-next v6 10/10] net: ethtool: Introduce ethtool command to list ports Maxime Chevallier
2026-03-06 13:58 ` [net-next,v6,10/10] " Simon Horman
2026-03-06 15:33 ` Maxime Chevallier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260306140911.495181-1-horms@kernel.org \
--to=horms@kernel.org \
--cc=andrew@lunn.ch \
--cc=christophe.leroy@csgroup.eu \
--cc=daniel@makrotopia.org \
--cc=davem@davemloft.net \
--cc=dimitri.fedrau@liebherr.com \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=herve.codina@bootlin.com \
--cc=hkallweit1@gmail.com \
--cc=kabel@kernel.org \
--cc=kory.maincent@bootlin.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=maxime.chevallier@bootlin.com \
--cc=mwojtas@chromium.org \
--cc=netdev@vger.kernel.org \
--cc=nicveronese@gmail.com \
--cc=o.rempel@pengutronix.de \
--cc=pabeni@redhat.com \
--cc=romain.gantois@bootlin.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=vladimir.oltean@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox