]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
cxl/port: Cleanup handling of the nr_dports 0 -> 1 transition
authorDan Williams <dan.j.williams@intel.com>
Sat, 31 Jan 2026 00:03:55 +0000 (16:03 -0800)
committerDave Jiang <dave.jiang@intel.com>
Mon, 2 Feb 2026 15:41:29 +0000 (08:41 -0700)
commit47fec713d97fb6b823026f723435b58af541bd8d
tree45abb0b59ee6f7fde99f2630d520f1d377f1b544
parent9a8920ca8ebfb99604f639e7fbc681d0d04518a0
cxl/port: Cleanup handling of the nr_dports 0 -> 1 transition

There are multiple setup actions that can occur for a switch port after it
is known that it has at least one active downstream link. That work is
currently split between __devm_cxl_add_dport(), the add_dport() helper, and
cxl_port_add_dport() where decoder setup occurs.

Clean this up by moving all @dport object setup responsibilities into
add_dport() and all port effects into cxl_port_add_dport().

add_dport() handles taking a reference on @dport->dport_dev, and
cxl_port_add_dport() grows the awareness to setup the port component
registers. This removes an awkward open-coded xa_erase() from the middle of
__devm_cxl_add_dport() and instead tasks cxl_port_add_dport() with calling
the common @dport destruction path if anything goes wrong.

After this @port->nr_dports is always the count of @dports in the
@port->dports xarray, and cxl_dport_remove() is symmetric with add_dport().
With ->nr_dports now reliably tracking the number of dports the use of
ida_is_empty() can be dropped. Recall that the ida is only cleared on
"release" of decoder objects, and release can be arbitrarily delayed past
unregistration.

Lastly port->component_reg_phys is no longer reset to CXL_RESOURCE_NONE
post setup, no reason is seen to carry that forward.

Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Tested-by: Terry Bowman <terry.bowman@amd.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Link: https://patch.msgid.link/20260131000403.2135324-2-dan.j.williams@intel.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
drivers/cxl/core/port.c