[PATCH v2] accel/qaic: drain the control workqueue before the device is freed

From: Yaohan Li

Date: Wed Nov 18 2026 - 21:29:46 EST


qaic_pci_remove() tears the MHI controller down and destroys the DRM
device, but nothing drains qdev->cntl_wq. qdev itself is allocated with
devm_kzalloc_flex() and is freed as soon as the PCI device is unbound,
while cntl_wq is a DRM-managed resource that survives until the last
open file drops its reference to the DRM device.

resp_work is queued from qaic_mhi_dl_xfer_cb() and resp_worker()
dereferences qdev, so a work item that is still queued, or still
running, when the driver instance goes away touches freed memory.

mhi_power_down() moves the controller to the shutdown state, disables
the interrupt and flushes the state worker that destroys the channel
devices, and mhi_unregister_controller() removes the controller, so no
data event can reach qaic_mhi_dl_xfer_cb() once
qaic_mhi_free_controller() has returned. Flushing the workqueue after
it therefore covers every work item that can still be queued.

Fixes: 22ec9a3b73dd ("accel/qaic: Leverage DRM managed APIs to release resources")
Signed-off-by: Yaohan Li <shunsheng1218@xxxxxxxxx>

---
Prepared against v7.4-rc1-1969-g666539eecdf4.

Compile tested only: arm64, aarch64-linux-gnu-gcc 11.4, CONFIG_DRM_ACCEL=y and
CONFIG_DRM_ACCEL_QAIC=m. No hardware was available, so the removal path was
not exercised and no race injection was run.

AI assistance: prepared with Claude (Anthropic) as a coding assistant; the
author reviewed the reasoning and takes responsibility for the content.

Changes in v2:
- Correct Fixes: to 22ec9a3b73dd, the commit that moved the device release
to DRM managed resources. No code change.
---
drivers/accel/qaic/qaic_drv.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/drivers/accel/qaic/qaic_drv.c b/drivers/accel/qaic/qaic_drv.c
index 90c0d31e414a..c4c3f450e67b 100644
--- a/drivers/accel/qaic/qaic_drv.c
+++ b/drivers/accel/qaic/qaic_drv.c
@@ -625,6 +625,15 @@ static void qaic_pci_remove(struct pci_dev *pdev)

qaic_dev_reset_clean_local_state(qdev);
qaic_mhi_free_controller(qdev->mhi_cntrl, link_up);
+
+ /*
+ * The control channel is gone, so nothing can queue resp_work any
+ * more. Drain it before qdev is freed: the workqueue belongs to the
+ * DRM device and may outlive this driver instance, and resp_worker()
+ * dereferences qdev.
+ */
+ flush_workqueue(qdev->cntl_wq);
+
qaic_destroy_drm_device(qdev, QAIC_NO_PARTITION);
}

--
2.34.1