[PATCH v5 03/14] KVM: ARM: Initial skeleton to compile KVM support

Christoffer Dall c.dall at virtualopensystems.com
Mon Jan 14 12:33:05 EST 2013


On Mon, Jan 14, 2013 at 11:24 AM, Russell King - ARM Linux
<linux at arm.linux.org.uk> wrote:
> On Tue, Jan 08, 2013 at 01:38:55PM -0500, Christoffer Dall wrote:
>> +     /* -ENOENT for unknown features, -EINVAL for invalid combinations. */
>> +     for (i = 0; i < sizeof(init->features)*8; i++) {
>> +             if (init->features[i / 32] & (1 << (i % 32))) {
>
> Isn't this an open-coded version of test_bit() ?

indeed, nicely spotted:

commit 608588674144e403ad0ea3c93066f3175bd5cf88
Author: Christoffer Dall <c.dall at virtualopensystems.com>
Date:   Mon Jan 14 12:30:07 2013 -0500

    KVM: ARM: Use test-bit instead of open-coded version

    Makes the code more readable, also adds spaces around the asterisk.

    Cc: Russell King <linux at arm.linux.org.uk>
    Signed-off-by: Christoffer Dall <c.dall at virtualopensystems.com>

diff --git a/arch/arm/kvm/guest.c b/arch/arm/kvm/guest.c
index 65ae563..2339d96 100644
--- a/arch/arm/kvm/guest.c
+++ b/arch/arm/kvm/guest.c
@@ -193,8 +193,8 @@ int kvm_vcpu_set_target(struct kvm_vcpu *vcpu,
 	bitmap_zero(vcpu->arch.features, KVM_VCPU_MAX_FEATURES);

 	/* -ENOENT for unknown features, -EINVAL for invalid combinations. */
-	for (i = 0; i < sizeof(init->features)*8; i++) {
-		if (init->features[i / 32] & (1 << (i % 32))) {
+	for (i = 0; i < sizeof(init->features) * 8; i++) {
+		if (test_bit(i, (void *)init->features)) {
 			if (i >= KVM_VCPU_MAX_FEATURES)
 				return -ENOENT;
 			set_bit(i, vcpu->arch.features);
--

Thanks,
-Christoffer



More information about the linux-arm-kernel mailing list