Skip to content

Commit 9799433

Browse files
Purva Yeshivinodkoul
authored andcommitted
dmaengine: idxd: cdev: Fix uninitialized use of sva in idxd_cdev_open
Fix Smatch-detected issue: drivers/dma/idxd/cdev.c:321 idxd_cdev_open() error: uninitialized symbol 'sva'. 'sva' pointer may be used uninitialized in error handling paths. Specifically, if PASID support is enabled and iommu_sva_bind_device() returns an error, the code jumps to the cleanup label and attempts to call iommu_sva_unbind_device(sva) without ensuring that sva was successfully assigned. This triggers a Smatch warning about an uninitialized symbol. Initialize sva to NULL at declaration and add a check using IS_ERR_OR_NULL() before unbinding the device. This ensures the function does not use an invalid or uninitialized pointer during cleanup. Signed-off-by: Purva Yeshi <[email protected]> Reviewed-by: Dave Jiang <[email protected]> Acked-by: Vinicius Costa Gomes <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 0af2f6b commit 9799433

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/dma/idxd/cdev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
222222
struct idxd_wq *wq;
223223
struct device *dev, *fdev;
224224
int rc = 0;
225-
struct iommu_sva *sva;
225+
struct iommu_sva *sva = NULL;
226226
unsigned int pasid;
227227
struct idxd_cdev *idxd_cdev;
228228

@@ -317,7 +317,7 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
317317
if (device_user_pasid_enabled(idxd))
318318
idxd_xa_pasid_remove(ctx);
319319
failed_get_pasid:
320-
if (device_user_pasid_enabled(idxd))
320+
if (device_user_pasid_enabled(idxd) && !IS_ERR_OR_NULL(sva))
321321
iommu_sva_unbind_device(sva);
322322
failed:
323323
mutex_unlock(&wq->wq_lock);

0 commit comments

Comments
 (0)