From: Dave Jiang <dave.jiang@intel.com>
To: linux-cxl@vger.kernel.org
Cc: dave@stgolabs.net, jonathan.cameron@huawei.com,
alison.schofield@intel.com, vishal.l.verma@intel.com,
ira.weiny@intel.com, dan.j.williams@intel.com
Subject: [PATCH v2 3/3] cxl: Clean up cxl_nvdimm devices when removing nvdimm_bus
Date: Wed, 11 Feb 2026 16:26:30 -0700 [thread overview]
Message-ID: <20260211232630.480509-4-dave.jiang@intel.com> (raw)
In-Reply-To: <20260211232630.480509-1-dave.jiang@intel.com>
In the current implementation, when the nvdimm_bus is removed, the
cxl_nvdimm devices only have the driver unbound which leaves orphaned
cxl_nvdimm devices around. Add removal of cxl_nvdimm devices when the
nvdimm_bus object is removed on cxl_nvb driver removal.
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
drivers/cxl/core/pmem.c | 6 +++++-
drivers/cxl/cxl.h | 1 +
drivers/cxl/pmem.c | 5 +++++
3 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/cxl/core/pmem.c b/drivers/cxl/core/pmem.c
index f7f784047450..4edc87ceb993 100644
--- a/drivers/cxl/core/pmem.c
+++ b/drivers/cxl/core/pmem.c
@@ -142,18 +142,22 @@ static struct cxl_nvdimm *cxl_nvdimm_alloc(struct cxl_nvdimm_bridge *cxl_nvb,
return cxl_nvd;
}
-static void cxlmd_release_nvdimm(void *_cxlmd)
+void cxlmd_release_nvdimm(void *_cxlmd)
{
struct cxl_memdev *cxlmd = _cxlmd;
struct cxl_nvdimm *cxl_nvd = cxlmd->cxl_nvd;
struct cxl_nvdimm_bridge *cxl_nvb = cxlmd->cxl_nvb;
+ dev_info(&cxlmd->dev, "XXX release nvdimm %s\n",
+ cxl_nvd ? dev_name(&cxl_nvd->dev) : "none");
+
cxl_nvd->cxlmd = NULL;
cxlmd->cxl_nvd = NULL;
cxlmd->cxl_nvb = NULL;
device_unregister(&cxl_nvd->dev);
put_device(&cxl_nvb->dev);
}
+EXPORT_SYMBOL_NS_GPL(cxlmd_release_nvdimm, "CXL");
/**
* devm_cxl_add_nvdimm() - add a bridge between a cxl_memdev and an nvdimm
diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
index 3b79d5c4765a..3f0d927e5772 100644
--- a/drivers/cxl/cxl.h
+++ b/drivers/cxl/cxl.h
@@ -926,6 +926,7 @@ bool is_cxl_nvdimm(struct device *dev);
int devm_cxl_add_nvdimm(struct device *host, struct cxl_port *port,
struct cxl_memdev *cxlmd);
struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(struct cxl_port *port);
+void cxlmd_release_nvdimm(void *cxlmd);
#ifdef CONFIG_CXL_REGION
bool is_cxl_pmem_region(struct device *dev);
diff --git a/drivers/cxl/pmem.c b/drivers/cxl/pmem.c
index 0b200be1fd36..edce5269a682 100644
--- a/drivers/cxl/pmem.c
+++ b/drivers/cxl/pmem.c
@@ -397,6 +397,7 @@ static int cxl_pmem_ctl(struct nvdimm_bus_descriptor *nd_desc,
static int detach_nvdimm(struct device *dev, void *data)
{
struct cxl_nvdimm *cxl_nvd;
+ struct cxl_memdev *cxlmd;
bool release = false;
if (!is_cxl_nvdimm(dev))
@@ -411,6 +412,10 @@ static int detach_nvdimm(struct device *dev, void *data)
}
if (release)
device_release_driver(dev);
+
+ cxlmd = cxl_nvd->cxlmd;
+ devm_release_action(&cxlmd->dev, cxlmd_release_nvdimm, cxlmd);
+
return 0;
}
--
2.52.0
next prev parent reply other threads:[~2026-02-11 23:26 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-11 23:26 [PATCH v2 0/3] cxl: Fix nvdimm_bus race for nvdimm devices Dave Jiang
2026-02-11 23:26 ` [PATCH v2 1/3] cxl: Move devm_cxl_add_nvdimm_bridge() to cxl_pmem.ko Dave Jiang
2026-02-11 23:46 ` dan.j.williams
2026-02-11 23:26 ` [PATCH v2 2/3] cxl: Fix race of nvdimm_bus object when creating nvdimm objects Dave Jiang
2026-02-11 23:55 ` dan.j.williams
2026-02-12 0:00 ` Dave Jiang
2026-02-11 23:26 ` Dave Jiang [this message]
2026-02-12 0:23 ` [PATCH v2 3/3] cxl: Clean up cxl_nvdimm devices when removing nvdimm_bus dan.j.williams
2026-02-12 6:01 ` kernel test robot
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=20260211232630.480509-4-dave.jiang@intel.com \
--to=dave.jiang@intel.com \
--cc=alison.schofield@intel.com \
--cc=dan.j.williams@intel.com \
--cc=dave@stgolabs.net \
--cc=ira.weiny@intel.com \
--cc=jonathan.cameron@huawei.com \
--cc=linux-cxl@vger.kernel.org \
--cc=vishal.l.verma@intel.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