[PATCH] nvdimm: virtio_pmem: reset the device if nvdimm_bus_register() fails

From: Yuho Choi

Date: Thu Dec 03 2026 - 00:07:59 EST


init_vq() enables the request queue on the device. If
nvdimm_bus_register() then fails, probe deletes the queue without
resetting the device, so the queue stays enabled and the next probe of
the device fails in setup_vq() with -ENOENT. Reset the device before
deleting the queue, as the later error path and remove() do.

Fixes: 6e84200c0a29 ("virtio-pmem: Add virtio pmem driver")
Signed-off-by: Yuho Choi <oss.patchbox@xxxxxxxxx>
---
I used an LLM to write and run the test below.

Tested on d06ce6f1eb5e in a QEMU/KVM guest with a virtio-pmem-pci device
and KASAN. A test-only module parameter made nvdimm_bus_register() fail
in the first probe; after clearing it, binding the driver again gave
(3 of 3 runs each):

without this patch:
virtio_pmem virtio0: failed to initialize virtio pmem vq's
virtio_pmem virtio0: probe with driver virtio_pmem failed with error -2
with this patch:
the bind succeeds and nd_pmem namespace0.0 is created

No KASAN reports in any run.

drivers/nvdimm/virtio_pmem.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/nvdimm/virtio_pmem.c b/drivers/nvdimm/virtio_pmem.c
index 3e06ff34c4af..e2b7fe50d181 100644
--- a/drivers/nvdimm/virtio_pmem.c
+++ b/drivers/nvdimm/virtio_pmem.c
@@ -117,6 +117,7 @@ static int virtio_pmem_probe(struct virtio_device *vdev)
if (!vpmem->nvdimm_bus) {
dev_err(&vdev->dev, "failed to register device with nvdimm_bus\n");
err = -ENXIO;
+ virtio_reset_device(vdev);
goto out_vq;
}


base-commit: d06ce6f1eb5eeffd4ebcfde345dc34a98131d106
--
2.56.1