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@xxxxxxxxxxxxxx/ Signed-off-by: Jakob Koschel <jakobkoschel@xxxxxxxxx> --- 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