فهرست منبع

KVM: x86: cleanup kvm_irq_delivery_to_apic_fast

Sparse is reporting a "we previously assumed 'src' could be null" error.
This is true as far as the static analyzer can see, but in practice only
IPIs can set shorthand to self and they also set 'src', so it's ok.
Still, move the initialization of x2apic_ipi (and thus the NULL check for
src right before the first use.

While at it, initializing ret to "false" is somewhat confusing because of
the almost immediate assigned of "true" to the same variable.  Thus,
initialize it to "true" and modify it in the only path that used to use
the value from "bool ret = false".  There is no change in generated code
from this change.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Paolo Bonzini 10 سال پیش
والد
کامیت
bea15428b9
1فایلهای تغییر یافته به همراه6 افزوده شده و 5 حذف شده
  1. 6 5
      arch/x86/kvm/lapic.c

+ 6 - 5
arch/x86/kvm/lapic.c

@@ -683,8 +683,7 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src,
 	unsigned long bitmap = 1;
 	unsigned long bitmap = 1;
 	struct kvm_lapic **dst;
 	struct kvm_lapic **dst;
 	int i;
 	int i;
-	bool ret = false;
-	bool x2apic_ipi = src && apic_x2apic_mode(src);
+	bool ret, x2apic_ipi;
 
 
 	*r = -1;
 	*r = -1;
 
 
@@ -696,16 +695,18 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src,
 	if (irq->shorthand)
 	if (irq->shorthand)
 		return false;
 		return false;
 
 
+	x2apic_ipi = src && apic_x2apic_mode(src);
 	if (irq->dest_id == (x2apic_ipi ? X2APIC_BROADCAST : APIC_BROADCAST))
 	if (irq->dest_id == (x2apic_ipi ? X2APIC_BROADCAST : APIC_BROADCAST))
 		return false;
 		return false;
 
 
+	ret = true;
 	rcu_read_lock();
 	rcu_read_lock();
 	map = rcu_dereference(kvm->arch.apic_map);
 	map = rcu_dereference(kvm->arch.apic_map);
 
 
-	if (!map)
+	if (!map) {
+		ret = false;
 		goto out;
 		goto out;
-
-	ret = true;
+	}
 
 
 	if (irq->dest_mode == APIC_DEST_PHYSICAL) {
 	if (irq->dest_mode == APIC_DEST_PHYSICAL) {
 		if (irq->dest_id >= ARRAY_SIZE(map->phys_map))
 		if (irq->dest_id >= ARRAY_SIZE(map->phys_map))