Re: [PATCH v3 2/2] cxl: Fix race of nvdimm_bus object when creating nvdimm objects

Gregory Price
2026-02-23T22:18:31Z

On Fri, Feb 13, 2026 at 03:40:38PM -0700, Dave Jiang wrote:
> @@ -248,6 +262,19 @@ int devm_cxl_add_nvdimm(struct device *host, struct cxl_port *port,
> if (!cxl_nvb)
> return -ENODEV;
>
> + /*
> + * Take the uport_dev lock to guard against race of nvdimm_bus object.
> + * cxl_acpi_probe() registers the nvdimm_bus and is done under the
> + * root port uport_dev lock.
> + *
> + * Take the cxl_nvb device lock to ensure that cxl_nvb driver is in a
> + * consistent state. And the driver registers nvdimm_bus.
> + */
> + guard(device)(cxl_nvb->port->uport_dev);
> + guard(device)(&cxl_nvb->dev);
> + if (!cxl_nvb->nvdimm_bus)
> + return -ENODEV;
> +

I think this leaks the reference on cxl_nvb taken by

devm_cxl_add_nvdimm()
device_find_child()

Maybe:
if (!cxl_nvb->nvdimm_bus) {
rc = -ENODEV;
goto err_alloc;
}

Reported-by: kreview-0811365

~Gregory