lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20220324073110.66125-1-jakobkoschel@gmail.com>
Date:   Thu, 24 Mar 2022 08:31:10 +0100
From:   Jakob Koschel <jakobkoschel@...il.com>
To:     Alex Williamson <alex.williamson@...hat.com>
Cc:     Cornelia Huck <cohuck@...hat.com>, kvm@...r.kernel.org,
        linux-kernel@...r.kernel.org, Mike Rapoport <rppt@...nel.org>,
        "Brian Johannesmeyer" <bjohannesmeyer@...il.com>,
        Cristiano Giuffrida <c.giuffrida@...nl>,
        "Bos, H.J." <h.j.bos@...nl>, Jakob Koschel <jakobkoschel@...il.com>
Subject: [PATCH] vfio/spapr_tce: replace usage of found with dedicated list iterator variable

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@...il.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ