[PATCH 5/6] dmaengine: idxd: Fix error code handling in idxd_cdev_open()
From: Vinicius Costa Gomes
Date: Mon Oct 12 2026 - 17:44:25 EST
idxd_cdev_open() mishandles rc on two error paths:
- On ida_alloc() failure it jumps to failed_ida without setting rc,
returning the leftover 0 from the earlier successful xa_insert(), so
open() falsely reports success.
- When a PASID entry already exists, xa_insert() returns -EBUSY. This
is non-fatal and only warned about, but rc is left negative and can
leak out for a shared wq (which skips the idxd_wq_set_pasid() branch
that would reset it).
Set rc to the ida_alloc() error before unwinding, and reset rc to 0
after the "PASID already exists" (Fixed the "exist -> exists" typo
while at it) warning.
Fixes: e6fd6d7e5f0f ("dmaengine: idxd: add a device to represent the file opened")
Fixes: b022f59725f0 ("dmaengine: idxd: add idxd_copy_cr() to copy user completion record during page fault handling")
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@xxxxxxxxx>
---
drivers/dma/idxd/cdev.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/dma/idxd/cdev.c b/drivers/dma/idxd/cdev.c
index 82b07cf942ef..abbab9bdd06c 100644
--- a/drivers/dma/idxd/cdev.c
+++ b/drivers/dma/idxd/cdev.c
@@ -264,8 +264,11 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
mutex_lock(&wq->uc_lock);
rc = xa_insert(&wq->upasid_xa, pasid, ctx, GFP_KERNEL);
mutex_unlock(&wq->uc_lock);
- if (rc < 0)
- dev_warn(dev, "PASID entry already exist in xarray.\n");
+ if (rc < 0) {
+ /* An existing entry is harmless, warn and continue */
+ dev_warn(dev, "PASID entry already exists in xarray.\n");
+ rc = 0;
+ }
if (wq_dedicated(wq)) {
rc = idxd_wq_set_pasid(wq, pasid);
@@ -279,6 +282,7 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
idxd_cdev = wq->idxd_cdev;
ctx->id = ida_alloc(&file_ida, GFP_KERNEL);
if (ctx->id < 0) {
+ rc = ctx->id;
dev_warn(dev, "ida alloc failure\n");
goto failed_ida;
}
--
2.56.0