Module Name:    src
Committed By:   cherry
Date:           Sat Aug 13 17:23:42 UTC 2011

Modified Files:
        src/sys/arch/xen/xen: evtchn.c

Log Message:
Use spin mutices correctly.
 - Prune redundant splxx()/splx() pairs.
 - Do not "leak" a mutex_spin_enter() via conditional return.

Thanks rmind@


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/xen/xen/evtchn.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/xen/xen/evtchn.c
diff -u src/sys/arch/xen/xen/evtchn.c:1.50 src/sys/arch/xen/xen/evtchn.c:1.51
--- src/sys/arch/xen/xen/evtchn.c:1.50	Thu Aug 11 17:59:00 2011
+++ src/sys/arch/xen/xen/evtchn.c	Sat Aug 13 17:23:42 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.c,v 1.50 2011/08/11 17:59:00 cherry Exp $	*/
+/*	$NetBSD: evtchn.c,v 1.51 2011/08/13 17:23:42 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.50 2011/08/11 17:59:00 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.51 2011/08/13 17:23:42 cherry Exp $");
 
 #include "opt_xen.h"
 #include "isa.h"
@@ -336,9 +336,7 @@
 {
 	evtchn_op_t op;
 	evtchn_port_t evtchn;
-	int s;
 
-	s = splhigh();
 	mutex_spin_enter(&evtchn_lock);
 
 	evtchn = vcpu_ipi_to_evtch[vcpu];
@@ -355,7 +353,6 @@
 	evtch_bindcount[evtchn]++;
 
 	mutex_spin_exit(&evtchn_lock);
-	splx(s);
     
 	return evtchn;
 }
@@ -364,9 +361,8 @@
 bind_virq_to_evtch(int virq)
 {
 	evtchn_op_t op;
-	int evtchn, s;
+	int evtchn;
 
-	s = splhigh();
 	mutex_spin_enter(&evtchn_lock);
 
 	/* 
@@ -379,6 +375,7 @@
 	struct cpu_info *ci = curcpu();
 
 	if (virq == VIRQ_DEBUG && ci != &cpu_info_primary) {
+		mutex_spin_exit(&evtchn_lock);
 		return -1;
 	}
 
@@ -402,7 +399,6 @@
 	evtch_bindcount[evtchn]++;
 
 	mutex_spin_exit(&evtchn_lock);
-	splx(s);
     
 	return evtchn;
 }
@@ -412,7 +408,6 @@
 {
 	evtchn_op_t op;
 	int evtchn;
-	int s;
 
 	struct cpu_info *ci = curcpu();
 
@@ -427,7 +422,6 @@
 		return -1;
 	}
 
-	s = splhigh();
 	mutex_spin_enter(&evtchn_lock);
 
 	evtch_bindcount[evtchn]--;
@@ -441,7 +435,6 @@
 	}
 
 	mutex_spin_exit(&evtchn_lock);
-	splx(s);
 
 	return evtchn;
 }
@@ -451,13 +444,12 @@
 bind_pirq_to_evtch(int pirq)
 {
 	evtchn_op_t op;
-	int evtchn, s;
+	int evtchn;
 
 	if (pirq >= NR_PIRQS) {
 		panic("pirq %d out of bound, increase NR_PIRQS", pirq);
 	}
 
-	s = splhigh();
 	mutex_spin_enter(&evtchn_lock);
 
 	evtchn = pirq_to_evtch[pirq];
@@ -478,7 +470,6 @@
 	evtch_bindcount[evtchn]++;
 
 	mutex_spin_exit(&evtchn_lock);
-	splx(s);
     
 	return evtchn;
 }
@@ -488,7 +479,6 @@
 {
 	evtchn_op_t op;
 	int evtchn = pirq_to_evtch[pirq];
-	int s = splhigh();
 
 	mutex_spin_enter(&evtchn_lock);
 
@@ -503,7 +493,6 @@
 	}
 
 	mutex_spin_exit(&evtchn_lock);
-	splx(s);
 
 	return evtchn;
 }
@@ -650,7 +639,7 @@
 		 * is more explicitly implemented.
 		 */
 		evts->ev_cpu = ci; 
-		mutex_init(&evtlock[evtch], MUTEX_DEFAULT, IPL_VM);
+		mutex_init(&evtlock[evtch], MUTEX_DEFAULT, IPL_HIGH);
 		evtsource[evtch] = evts;
 		if (evname)
 			strncpy(evts->ev_evname, evname,

Reply via email to