Add valid_vcpu() helper.
PATCH 1/1 Add valid_vcpu() helper.
Consolidate the logic for checking whether a vcpu index is valid. Also, use likely(), as a valid value should be the overwhelmingly common case.
Signed-off-by James Morris <jmorris-gx6/[email protected]>
--- drivers/kvm/kvm_main.c | 23 ++++++++++++++--------- 1 files changed, 14 insertions(+), 9 deletions(-)
drivers/kvm/kvm_main.c +14 -9
@@ -72,6 +72,11 @@ #define CR4_RESEVED_BITS (~((1ULL << 11)#define CR8_RESEVED_BITS (~0x0fULL)#define EFER_RESERVED_BITS 0xfffffffffffff2fe +static inline int valid_vcpu (int n) +{ +return likely (n >=0 && n <KVM_MAX_VCPUS ); +} +struct vmx_msr_entry *find_msr_entry (struct kvm_vcpu *vcpu,u32 msr) {int i;
@@ -506,7 +511,7 @@ static int kvm_dev_ioctl_create_vcpu(strstruct kvm_vcpu *vcpu; r = -EINVAL ; -if (n <0 || n >=KVM_MAX_VCPUS ) +if (!valid_vcpu (n)) goto out; vcpu = &kvm->vcpus[n];
@@ -1197,7 +1202,7 @@ static int kvm_dev_ioctl_run(struct kvmstruct kvm_vcpu *vcpu;int r; -if (kvm_run->vcpu <0 || kvm_run->vcpu >=KVM_MAX_VCPUS ) +if (!valid_vcpu (kvm_run->vcpu))return -EINVAL ; vcpu =vcpu_load (kvm, kvm_run->vcpu);
@@ -1226,7 +1231,7 @@ static int kvm_dev_ioctl_get_regs(struct {struct kvm_vcpu *vcpu; -if (regs->vcpu <0 || regs->vcpu >=KVM_MAX_VCPUS ) +if (!valid_vcpu (regs->vcpu))return -EINVAL ; vcpu =vcpu_load (kvm, regs->vcpu);
@@ -1272,7 +1277,7 @@ static int kvm_dev_ioctl_set_regs(struct {struct kvm_vcpu *vcpu; -if (regs->vcpu <0 || regs->vcpu >=KVM_MAX_VCPUS ) +if (!valid_vcpu (regs->vcpu))return -EINVAL ; vcpu =vcpu_load (kvm, regs->vcpu);
@@ -1319,7 +1324,7 @@ static int kvm_dev_ioctl_get_sregs(strucstruct kvm_vcpu *vcpu;struct descriptor_table dt; -if (sregs->vcpu <0 || sregs->vcpu >=KVM_MAX_VCPUS ) +if (!valid_vcpu (sregs->vcpu))return -EINVAL ; vcpu =vcpu_load (kvm, sregs->vcpu);if (!vcpu)
@@ -1371,7 +1376,7 @@ static int kvm_dev_ioctl_set_sregs(strucint i;struct descriptor_table dt; -if (sregs->vcpu <0 || sregs->vcpu >=KVM_MAX_VCPUS ) +if (!valid_vcpu (sregs->vcpu))return -EINVAL ; vcpu =vcpu_load (kvm, sregs->vcpu);if (!vcpu)
@@ -1462,7 +1467,7 @@ static int __msr_io(struct kvm *kvm, strstruct kvm_vcpu *vcpu;int i; -if (msrs->vcpu <0 || msrs->vcpu >=KVM_MAX_VCPUS ) +if (!valid_vcpu (msrs->vcpu))return -EINVAL ; vcpu =vcpu_load (kvm, msrs->vcpu);
@@ -1555,7 +1560,7 @@ static int kvm_dev_ioctl_interrupt(struc {struct kvm_vcpu *vcpu; -if (irq->vcpu <0 || irq->vcpu >=KVM_MAX_VCPUS ) +if (!valid_vcpu (irq->vcpu))return -EINVAL ;if (irq->irq <0 || irq->irq >=256 )return -EINVAL ;
@@ -1577,7 +1582,7 @@ static int kvm_dev_ioctl_debug_guest(strstruct kvm_vcpu *vcpu;int r; -if (dbg->vcpu <0 || dbg->vcpu >=KVM_MAX_VCPUS ) +if (!valid_vcpu (dbg->vcpu))return -EINVAL ; vcpu =vcpu_load (kvm, dbg->vcpu);if (!vcpu)
Signature · 8 lines
1.4.2.4 ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Avi Kivity
AppliedQuoted 4 lines · James Morris
Consolidate the logic for checking whether a vcpu index is valid. Also, use
likely(), as a valid value should be the overwhelmingly common case.
Applied, thanks.
Signature · 8 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV