git: 08055452cbf2 - main - libkvm: fix kvm_walk_pages

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Fri, 10 Dec 2021 19:15:54 UTC
The branch main has been updated by emaste:

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

commit 08055452cbf24a3cea48cb4f665bab78d89b7a39
Author:     Bora Özarslan <borako.ozarslan@gmail.com>
AuthorDate: 2021-11-25 19:09:26 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2021-12-10 19:15:15 +0000

    libkvm: fix kvm_walk_pages
    
    Correct bitmap operations in _kvm_bitmap_next.
    
    Reviewed by:    jhb
    MFC after:      2 weeks
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D19183
---
 lib/libkvm/kvm_private.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/libkvm/kvm_private.c b/lib/libkvm/kvm_private.c
index d853d1643101..a45f66caf2fe 100644
--- a/lib/libkvm/kvm_private.c
+++ b/lib/libkvm/kvm_private.c
@@ -792,8 +792,8 @@ _kvm_bitmap_next(struct kvm_bitmap *bm, u_long *idx)
 
 	/* Find the next valid idx. */
 	for (; *idx < first_invalid; (*idx)++) {
-		unsigned int mask = *idx % CHAR_BIT;
-		if ((bm->map[*idx * CHAR_BIT] & mask) == 0)
+		unsigned int mask = 1U << (*idx % CHAR_BIT);
+		if ((bm->map[*idx / CHAR_BIT] & mask) != 0)
 			break;
 	}