git: a982814ef8dd - stable/13 - vmm: Avoid infinite loop in vcpu_lock_all error case.

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Thu, 26 Jan 2023 22:12:23 UTC
The branch stable/13 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=a982814ef8dd0c2fb8fd935341a3cd354791d31c

commit a982814ef8dd0c2fb8fd935341a3cd354791d31c
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-12-09 18:26:49 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2023-01-26 22:07:33 +0000

    vmm: Avoid infinite loop in vcpu_lock_all error case.
    
    Reported by:    Coverity (CIDs 1501060,1501071)
    Reviewed by:    corvink, markj, emaste
    Differential Revision:  https://reviews.freebsd.org/D37648
    
    (cherry picked from commit d212d6ebb4ea3b3e9c3964c1a6d3f41817e437e1)
---
 sys/amd64/vmm/vmm_dev.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sys/amd64/vmm/vmm_dev.c b/sys/amd64/vmm/vmm_dev.c
index 94b462feef6a..2d8ff43a74dd 100644
--- a/sys/amd64/vmm/vmm_dev.c
+++ b/sys/amd64/vmm/vmm_dev.c
@@ -149,7 +149,7 @@ vcpu_lock_all(struct vmmdev_softc *sc)
 {
 	struct vcpu *vcpu;
 	int error;
-	uint16_t i, maxcpus;
+	uint16_t i, j, maxcpus;
 
 	vm_slock_vcpus(sc->vm);
 	maxcpus = vm_get_maxcpus(sc->vm);
@@ -163,11 +163,11 @@ vcpu_lock_all(struct vmmdev_softc *sc)
 	}
 
 	if (error) {
-		while (--i >= 0) {
-			vcpu = vm_vcpu(sc->vm, i);
+		for (j = 0; j < i; j++) {
+			vcpu = vm_vcpu(sc->vm, j);
 			if (vcpu == NULL)
 				continue;
-			vcpu_unlock_one(sc, i, vcpu);
+			vcpu_unlock_one(sc, j, vcpu);
 		}
 		vm_unlock_vcpus(sc->vm);
 	}