Skip to contentSkip to conversation

vfio/type1: Fix vfio_find_dma_valid return

PATCH Applied Anthony Yznaga 2 participants 2 messages Aug 23, 2021 – Aug 26, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 vfio/type1: Fix vfio_find_dma_valid return

vfio_find_dma_valid is defined to return WAITED on success if it was necessary to wait. However, the loop forgets the WAITED value returned by vfio_wait() and returns 0 in a later iteration. Fix it.

---
v3:
use Steve Sistare's suggested commit text and add his R-b
v2:
use Alex Williamson's simplified fix

 drivers/vfio/vfio_iommu_type1.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/vfio/vfio_iommu_type1.c +4 -4
index 0b4f7c174c7a..0e9217687f5c 100644
@@ -612,17 +612,17 @@ static int vfio_wait(struct vfio_iommu *iommu)
 static int vfio_find_dma_valid(struct vfio_iommu *iommu, dma_addr_t start,
 			       size_t size, struct vfio_dma **dma_p)
 {
-	int ret;
+	int ret = 0;
 
 	do {
 		*dma_p = vfio_find_dma(iommu, start, size);
 		if (!*dma_p)
-			ret = -EINVAL;
+			return -EINVAL;
 		else if (!(*dma_p)->vaddr_invalid)
-			ret = 0;
+			return ret;
 		else
 			ret = vfio_wait(iommu);
-	} while (ret > 0);
+	} while (ret == WAITED);
 
 	return ret;
 }
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 7 lines · On Mon, 23 Aug 2021 09:35:50 -0700 Anthony Yznaga <[email protected]>…

vfio_find_dma_valid is defined to return WAITED on success if it was necessary to wait. However, the loop forgets the WAITED value returned by vfio_wait() and returns 0 in a later iteration. Fix it.

Quoted 8 lines

---
v3:
use Steve Sistare's suggested commit text and add his R-b
v2:
use Alex Williamson's simplified fix

 drivers/vfio/vfio_iommu_type1.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Applied to vfio next branch for v5.15. Thanks,

Alex