linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vfio/spapr_tce: replace usage of found with dedicated list iterator variable
@ 2022-03-24  7:31 Jakob Koschel
  0 siblings, 0 replies; only message in thread
From: Jakob Koschel @ 2022-03-24  7:31 UTC (permalink / raw)
  To: Alex Williamson
  Cc: Cornelia Huck, kvm, linux-kernel, Mike Rapoport,
	Brian Johannesmeyer, Cristiano Giuffrida, Bos, H.J.,
	Jakob Koschel

To move the list iterator variable into the list_for_each_entry_*()
macro in the future it should be avoided to use the list iterator
variable after the loop body.

To *never* use the list iterator variable after the loop it was
concluded to use a separate iterator variable instead of a
found boolean [1].

This removes the need to use a found variable and simply checking if
the variable was set, can determine if the break/goto was hit.

Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/
Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>
---
 drivers/vfio/vfio_iommu_spapr_tce.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_spapr_tce.c
index 708a95e61831..f64ef767909a 100644
--- a/drivers/vfio/vfio_iommu_spapr_tce.c
+++ b/drivers/vfio/vfio_iommu_spapr_tce.c
@@ -104,8 +104,7 @@ static long tce_iommu_unregister_pages(struct tce_container *container,
 		__u64 vaddr, __u64 size)
 {
 	struct mm_iommu_table_group_mem_t *mem;
-	struct tce_iommu_prereg *tcemem;
-	bool found = false;
+	struct tce_iommu_prereg *tcemem = NULL, *iter;
 	long ret;
 
 	if ((vaddr & ~PAGE_MASK) || (size & ~PAGE_MASK))
@@ -115,14 +114,14 @@ static long tce_iommu_unregister_pages(struct tce_container *container,
 	if (!mem)
 		return -ENOENT;
 
-	list_for_each_entry(tcemem, &container->prereg_list, next) {
-		if (tcemem->mem == mem) {
-			found = true;
+	list_for_each_entry(iter, &container->prereg_list, next) {
+		if (iter->mem == mem) {
+			tcemem = iter;
 			break;
 		}
 	}
 
-	if (!found)
+	if (!tcemem)
 		ret = -ENOENT;
 	else
 		ret = tce_iommu_prereg_free(container, tcemem);
@@ -1330,19 +1329,19 @@ static void tce_iommu_detach_group(void *iommu_data,
 {
 	struct tce_container *container = iommu_data;
 	struct iommu_table_group *table_group;
-	bool found = false;
-	struct tce_iommu_group *tcegrp;
+	struct tce_iommu_group *tcegrp = NULL;
+	struct tce_iommu_group *iter;
 
 	mutex_lock(&container->lock);
 
-	list_for_each_entry(tcegrp, &container->group_list, next) {
-		if (tcegrp->grp == iommu_group) {
-			found = true;
+	list_for_each_entry(iter, &container->group_list, next) {
+		if (iter->grp == iommu_group) {
+			tcegrp = iter;
 			break;
 		}
 	}
 
-	if (!found) {
+	if (!tcegrp) {
 		pr_warn("tce_vfio: detaching unattached group #%u\n",
 				iommu_group_id(iommu_group));
 		goto unlock_exit;

base-commit: f443e374ae131c168a065ea1748feac6b2e76613
-- 
2.25.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-03-24  7:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24  7:31 [PATCH] vfio/spapr_tce: replace usage of found with dedicated list iterator variable Jakob Koschel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).