Changeset View
Changeset View
Standalone View
Standalone View
lib/libkvm/kvm_private.c
Show First 20 Lines • Show All 777 Lines • ▼ Show 20 Lines | _kvm_bitmap_set(struct kvm_bitmap *bm, u_long bm_index) | ||||
if (bm_index / 8 < bm->size) | if (bm_index / 8 < bm->size) | ||||
*byte |= (1UL << (bm_index % 8)); | *byte |= (1UL << (bm_index % 8)); | ||||
} | } | ||||
int | int | ||||
_kvm_bitmap_next(struct kvm_bitmap *bm, u_long *idx) | _kvm_bitmap_next(struct kvm_bitmap *bm, u_long *idx) | ||||
{ | { | ||||
u_long first_invalid = bm->size * CHAR_BIT; | u_long first_invalid = bm->size * CHAR_BIT; | ||||
will: Why? The constant makes clear this number is derived from the number of bits in an `bm->map`. | |||||
Not Done Inline ActionsI almost made the same comment (in the name of having a smaller diff), but then I noticed that _kvm_bitmap_set() uses bare 8's. jhb: I almost made the same comment (in the name of having a smaller diff), but then I noticed that… | |||||
Not Done Inline ActionsGood point, but if we are changing anything here, I'd fix that usage to match, rather than the other way around. will: Good point, but if we are changing anything here, I'd fix that usage to match, rather than the… | |||||
if (*idx == ULONG_MAX) | if (*idx == ULONG_MAX) | ||||
*idx = 0; | *idx = 0; | ||||
else | else | ||||
(*idx)++; | (*idx)++; | ||||
/* Find the next valid idx. */ | /* Find the next valid idx. */ | ||||
for (; *idx < first_invalid; (*idx)++) { | for (; *idx < first_invalid; (*idx)++) { | ||||
unsigned int mask = *idx % CHAR_BIT; | unsigned int mask = 1U << (*idx % CHAR_BIT); | ||||
if ((bm->map[*idx * CHAR_BIT] & mask) == 0) | if ((bm->map[*idx / CHAR_BIT] & mask) != 0) | ||||
Done Inline Actionsjust 1U I guess, will update locally emaste: just `1U` I guess, will update locally | |||||
break; | break; | ||||
} | } | ||||
return (*idx < first_invalid); | return (*idx < first_invalid); | ||||
} | } | ||||
void | void | ||||
_kvm_bitmap_deinit(struct kvm_bitmap *bm) | _kvm_bitmap_deinit(struct kvm_bitmap *bm) | ||||
Show All 23 Lines |
Why? The constant makes clear this number is derived from the number of bits in an bm->map.