Re: [PATCH v2 1/2] cxl/port: Hold port host lock while dport adding.

From: Li Ming

Date: Sun Feb 08 2026 - 07:07:19 EST



在 2026/2/8 01:28, dan.j.williams@xxxxxxxxx 写道:
Li Ming wrote:
[...]

diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c
index 5c82e6f32572..6f0d9fe439db 100644
--- a/drivers/cxl/core/port.c
+++ b/drivers/cxl/core/port.c
@@ -612,6 +612,23 @@ struct cxl_port *parent_port_of(struct cxl_port *port)
return port->parent_dport->port;
}
+static struct device *to_port_host(struct cxl_port *port)
+{
+ struct cxl_port *parent = parent_port_of(port);
+
+ /*
+ * The host of CXL root port and the first level of ports is
+ * the platform firmware device, the host of all other ports
+ * is their parent port.
+ */
+ if (!parent)
+ return port->uport_dev;
This helper looks good and this case is theoretically correct, but I
assume that find_or_add_dport() never hits this case, right?

Right.  This case is only for finding cxl root's host, find_or_add_dport() is

only used for cxl host bridge ports and cxl switch ports.

How about move the introduction of this helper to its own lead-in patch
and use it to replace the open coded version of this pattern in
unregister_port(), __devm_cxl_add_dport(), and endpoint_host().

Sure, will do it in next version, thanks for that.


Ming

I do notice you caught the one in unregister_port(), but there are more.

With that change you can add:

Reviewed-by: Dan Williams <dan.j.williams@xxxxxxxxx>