[PATCH] cxl/port: Do not return -EAGAIN from find_or_add_dport() for newly added dport
From: Li Ming
Date: Sat Mar 07 2026 - 00:53:19 EST
find_or_add_dport() is used to get an ancestor dport of a new CXL memdev
on an existing ancestor port. It is called only when all ancestor ports
of the given CXL memdev have been enumerated. Because port enumeration
iterator walks CXL hierarchy of a given CXL memdev from CXL memdev to
CXL root, if it found an unenumerated ancestor port but the parent port
of the port is existed, iterator will call add_port_attach_ep() to add
the absent port then trigger CXL hierarchy re-walk until all ancestor
ports of the given CXL memdev enumerated. After that, iterator just has
chance to call find_or_add_dport().
So if an ancestor port is existed but the corresponding dport for the
CXL memdev has not been added, iterator will use find_or_add_dport() to
add the dport then return -EAGAIN on success. The -EAGAIN will trigger a
CXL hierarchy re-walk.
However, this re-walk is unnecessary. After adding the ancestor dport,
subsequent calls to find_or_add_dport() will return the newly added
dport on the same ancestor port during re-walk. Therefore,
find_or_add_dport() can return the newly added dport directly instead of
an -EAGAIN, avoiding the unnecessary CXL hierarchy re-walk.
Signed-off-by: Li Ming <ming.li@xxxxxxxxxxxx>
---
drivers/cxl/core/port.c | 13 ++-----------
1 file changed, 2 insertions(+), 11 deletions(-)
diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c
index c5aacd7054f1..3074d912d6e5 100644
--- a/drivers/cxl/core/port.c
+++ b/drivers/cxl/core/port.c
@@ -1782,14 +1782,8 @@ static struct cxl_dport *find_or_add_dport(struct cxl_port *port,
guard(device)(port_to_host(port));
guard(device)(&port->dev);
dport = cxl_find_dport_by_dev(port, dport_dev);
- if (!dport) {
+ if (!dport)
dport = probe_dport(port, dport_dev);
- if (IS_ERR(dport))
- return dport;
-
- /* New dport added, restart iteration */
- return ERR_PTR(-EAGAIN);
- }
return dport;
}
@@ -1848,11 +1842,8 @@ int devm_cxl_enumerate_ports(struct cxl_memdev *cxlmd)
* have the dport added here.
*/
dport = find_or_add_dport(port, dport_dev);
- if (IS_ERR(dport)) {
- if (PTR_ERR(dport) == -EAGAIN)
- goto retry;
+ if (IS_ERR(dport))
return PTR_ERR(dport);
- }
rc = cxl_add_ep(dport, &cxlmd->dev);
---
base-commit: 19d2f0b97a131198efc2c4ca3eb7f980bba8c2b4
change-id: 20260307-find_or_add_dport_not_return_eagain-ab17727523c8
Best regards,
--
Li Ming <ming.li@xxxxxxxxxxxx>