mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] Convert backwards goto into a while loop
@ 2022-12-28 21:32 Shachar Raindel
  2023-01-03 17:43 ` Alex Williamson
  0 siblings, 1 reply; 3+ messages in thread
From: Shachar Raindel @ 2022-12-28 21:32 UTC (permalink / raw)
  To: Alex Williamson, Cornelia Huck; +Cc: kvm, linux-kernel, Shachar Raindel

The function vaddr_get_pfns used a goto retry structure to implement
retrying.  This is discouraged by the coding style guide (which is
only recommending goto for handling function exits). Convert the code
to a while loop, making it explicit that the follow block only runs
when the pin attempt failed.

Signed-off-by: Shachar Raindel <shacharr@google.com>
---
 drivers/vfio/vfio_iommu_type1.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 23c24fe98c00..7f38d7fc3f62 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -570,27 +570,28 @@ static int vaddr_get_pfns(struct mm_struct *mm, unsigned long vaddr,
 		}
 
 		*pfn = page_to_pfn(pages[0]);
-		goto done;
-	}
+	} else
+		do {
+
+			/* This is not a normal page, lookup PFN for P2P DMA */
+			vaddr = untagged_addr(vaddr);
 
-	vaddr = untagged_addr(vaddr);
+			vma = vma_lookup(mm, vaddr);
 
-retry:
-	vma = vma_lookup(mm, vaddr);
+			if (!vma || !(vma->vm_flags & VM_PFNMAP))
+				break;
 
-	if (vma && vma->vm_flags & VM_PFNMAP) {
-		ret = follow_fault_pfn(vma, mm, vaddr, pfn, prot & IOMMU_WRITE);
-		if (ret == -EAGAIN)
-			goto retry;
+			ret = follow_fault_pfn(vma, mm, vaddr, pfn,
+					       prot & IOMMU_WRITE);
+			if (ret)
+				continue; /* Retry for EAGAIN, otherwise bail */
 
-		if (!ret) {
 			if (is_invalid_reserved_pfn(*pfn))
 				ret = 1;
 			else
 				ret = -EFAULT;
-		}
-	}
-done:
+		} while (ret == -EAGAIN);
+
 	mmap_read_unlock(mm);
 	return ret;
 }
-- 
2.39.0.314.g84b9a713c41-goog


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-03 19:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-28 21:32 [PATCH] Convert backwards goto into a while loop Shachar Raindel
2023-01-03 17:43 ` Alex Williamson
2023-01-03 19:49   ` [PATCH v2] Convert backwards goto with " Shachar Raindel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®