Skip to contentSkip to conversation

Remove three magic numbers

PATCH Applied Rusty Russell 2 participants 2 messages Jul 30, 2007 1 message not in the archive KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Remove three magic numbers

There are several places where hardcoded numbers are used in place of the easily-available constant, which is poor form.

drivers/kvm/kvm_main.c +1 -1
diff -r 8bb74738cd07 drivers/kvm/kvm_main.c
@@ -2284,7 +2284,7 @@ static int kvm_vcpu_ioctl_interrupt(stru
 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
 				    struct kvm_interrupt *irq)
 {
-	if (irq->irq < 0 || irq->irq >= 256)
+	if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
 		return -EINVAL;
 	vcpu_load(vcpu);
 	push_irq(vcpu, irq->irq);
drivers/kvm/svm.c +1 -1
diff -r ca711ab5ba1a drivers/kvm/svm.c
@@ -241,7 +241,7 @@ static void skip_emulated_instruction(st
 		pr_debug("%s: NOP\n", __FUNCTION__);
 		return;
 	}
-	if (svm->next_rip - svm->vmcb->save.rip > 15) {
+	if (svm->next_rip - svm->vmcb->save.rip > MAX_INST_SIZE) {
 		printk(KERN_ERR "%s: ip 0x%llx next 0x%llx\n",
 		       __FUNCTION__,
 		       svm->vmcb->save.rip,
drivers/kvm/kvm_main.c +1 -1
diff -r 0b74682d8925 drivers/kvm/kvm_main.c
@@ -354,7 +354,7 @@ static void free_pio_guest_pages(struct 
 {
 	int i;
 
-	for (i = 0; i < 2; ++i)
+	for (i = 0; i < ARRAY_SIZE(vcpu->pio.guest_pages); ++i)
 		if (vcpu->pio.guest_pages[i]) {
 			__free_page(vcpu->pio.guest_pages[i]);
 			vcpu->pio.guest_pages[i] = NULL;

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

A message that is not in the archive (sent off-list or not yet received): 1185777717.12151.160.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]

Applied
#2 lore raw
Quoted 4 lines · Rusty Russell

There are several places where hardcoded numbers are used in place of the easily-available constant, which is poor form.

Applied, thanks.

Signature · 8 lines
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/