[zaptel-commits] mattf: branch 1.2 r2464 - /branches/1.2/wcte11xp.c

zaptel-commits at lists.digium.com zaptel-commits at lists.digium.com
Sat Apr 28 12:04:50 MST 2007


Author: mattf
Date: Sat Apr 28 14:04:50 2007
New Revision: 2464

URL: http://svn.digium.com/view/zaptel?view=rev&rev=2464
Log:
Fix for potential deadlock in drivers

Modified:
    branches/1.2/wcte11xp.c

Modified: branches/1.2/wcte11xp.c
URL: http://svn.digium.com/view/zaptel/branches/1.2/wcte11xp.c?view=diff&rev=2464&r1=2463&r2=2464
==============================================================================
--- branches/1.2/wcte11xp.c (original)
+++ branches/1.2/wcte11xp.c Sat Apr 28 14:04:50 2007
@@ -549,24 +549,35 @@
 	return 0;
 }
 
-static void __t1_check_sigbits(struct t1 *wc)
+static void t1_check_sigbits(struct t1 *wc)
 {
 	int a,i,rxs;
+	unsigned long flags;
+
 	if (!(wc->span.flags & ZT_FLAG_RUNNING))
 		return;
+
+	spin_lock_irqsave(&wc->lock, flags);
+
 	if (wc->spantype == TYPE_E1) {
 		for (i = 0; i < 15; i++) {
 			a = __t1_framer_in(wc, 0x71 + i);
 			/* Get high channel in low bits */
 			rxs = (a & 0xf);
 			if (!(wc->span.chans[i+16].sig & ZT_SIG_CLEAR)) {
-				if (wc->span.chans[i+16].rxsig != rxs)
+				if (wc->span.chans[i+16].rxsig != rxs) {
+					spin_unlock_irqrestore(&wc->lock, flags);
 					zt_rbsbits(&wc->span.chans[i+16], rxs);
+					spin_lock_irqsave(&wc->lock, flags);
+				}
 			}
 			rxs = (a >> 4) & 0xf;
 			if (!(wc->span.chans[i].sig & ZT_SIG_CLEAR)) {
-				if (wc->span.chans[i].rxsig != rxs)
+				if (wc->span.chans[i].rxsig != rxs) {
+					spin_unlock_irqrestore(&wc->lock, flags);
 					zt_rbsbits(&wc->span.chans[i], rxs);
+					spin_lock_irqsave(&wc->lock, flags);
+				}
 			}
 		}
 	} else if (wc->span.lineconfig & ZT_CONFIG_D4) {
@@ -575,23 +586,35 @@
 			/* Get high channel in low bits */
 			rxs = (a & 0x3) << 2;
 			if (!(wc->span.chans[i+3].sig & ZT_SIG_CLEAR)) {
-				if (wc->span.chans[i+3].rxsig != rxs)
+				if (wc->span.chans[i+3].rxsig != rxs) {
+					spin_unlock_irqrestore(&wc->lock, flags);
 					zt_rbsbits(&wc->span.chans[i+3], rxs);
+					spin_lock_irqsave(&wc->lock, flags);
+				}
 			}
 			rxs = (a & 0xc);
 			if (!(wc->span.chans[i+2].sig & ZT_SIG_CLEAR)) {
-				if (wc->span.chans[i+2].rxsig != rxs)
+				if (wc->span.chans[i+2].rxsig != rxs) {
+					spin_unlock_irqrestore(&wc->lock, flags);
 					zt_rbsbits(&wc->span.chans[i+2], rxs);
+					spin_lock_irqsave(&wc->lock, flags);
+				}
 			}
 			rxs = (a >> 2) & 0xc;
 			if (!(wc->span.chans[i+1].sig & ZT_SIG_CLEAR)) {
-				if (wc->span.chans[i+1].rxsig != rxs)
+				if (wc->span.chans[i+1].rxsig != rxs) {
+					spin_unlock_irqrestore(&wc->lock, flags);
 					zt_rbsbits(&wc->span.chans[i+1], rxs);
+					spin_lock_irqsave(&wc->lock, flags);
+				}
 			}
 			rxs = (a >> 4) & 0xc;
 			if (!(wc->span.chans[i].sig & ZT_SIG_CLEAR)) {
-				if (wc->span.chans[i].rxsig != rxs)
+				if (wc->span.chans[i].rxsig != rxs) {
+					spin_unlock_irqrestore(&wc->lock, flags);
 					zt_rbsbits(&wc->span.chans[i], rxs);
+					spin_lock_irqsave(&wc->lock, flags);
+				}
 			}
 		}
 	} else {
@@ -600,16 +623,23 @@
 			/* Get high channel in low bits */
 			rxs = (a & 0xf);
 			if (!(wc->span.chans[i+1].sig & ZT_SIG_CLEAR)) {
-				if (wc->span.chans[i+1].rxsig != rxs)
+				if (wc->span.chans[i+1].rxsig != rxs) {
+					spin_unlock_irqrestore(&wc->lock, flags);
 					zt_rbsbits(&wc->span.chans[i+1], rxs);
+					spin_lock_irqsave(&wc->lock, flags);
+				}
 			}
 			rxs = (a >> 4) & 0xf;
 			if (!(wc->span.chans[i].sig & ZT_SIG_CLEAR)) {
-				if (wc->span.chans[i].rxsig != rxs)
+				if (wc->span.chans[i].rxsig != rxs) {
+					spin_unlock_irqrestore(&wc->lock, flags);
 					zt_rbsbits(&wc->span.chans[i], rxs);
+					spin_lock_irqsave(&wc->lock, flags);
+				}
 			}
 		}
 	}
+	spin_unlock_irqrestore(&wc->lock, flags);
 }
 
 static void t4_serial_setup(struct t1 *wc)
@@ -1122,14 +1152,17 @@
 	zt_receive(&wc->span);
 }
 
-static void __t1_check_alarms(struct t1 *wc)
+static void t1_check_alarms(struct t1 *wc)
 {
 	unsigned char c,d;
 	int alarms;
 	int x,j;
+	unsigned long flags;
 
 	if (!(wc->span.flags & ZT_FLAG_RUNNING))
 		return;
+
+	spin_lock_irqsave(&wc->lock, flags);
 
 	c = __t1_framer_in(wc, 0x4c);
 	if (wc->spanflags & FLAG_FALC12)
@@ -1243,18 +1276,25 @@
 	if (wc->span.mainttimer || wc->span.maintstat) 
 		alarms |= ZT_ALARM_LOOPBACK;
 	wc->span.alarms = alarms;
+	spin_unlock_irqrestore(&wc->lock, flags);
 	zt_alarm_notify(&wc->span);
 }
 
 
-static void __t1_do_counters(struct t1 *wc)
-{
+static void t1_do_counters(struct t1 *wc)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&wc->lock, flags);
 	if (wc->alarmtimer) {
 		if (!--wc->alarmtimer) {
 			wc->span.alarms &= ~(ZT_ALARM_RECOVER);
+			spin_unlock_irqrestore(&wc->lock, flags);
 			zt_alarm_notify(&wc->span);
+			spin_lock_irqsave(&wc->lock, flags);
 		}
 	}
+	spin_unlock_irqrestore(&wc->lock, flags);
 }
 
 ZAP_IRQ_HANDLER(t1xxp_interrupt)
@@ -1292,8 +1332,10 @@
 	__handle_leds(wc);
 #endif
 
+	spin_unlock_irqrestore(&wc->lock, flags);
+
 	/* Count down timers */
-	__t1_do_counters(wc);
+	t1_do_counters(wc);
 
 	/* Do some things that we don't have to do very often */
 	x = wc->intcount & 15 /* 63 */;
@@ -1302,17 +1344,15 @@
 	case 1:
 		break;
 	case 2:
-		__t1_check_sigbits(wc);
+		t1_check_sigbits(wc);
 		break;
 	case 4:
 		/* Check alarms 1/4 as frequently */
 		if (!(wc->intcount & 0x30))
-			__t1_check_alarms(wc);
+			t1_check_alarms(wc);
 		break;
 	}
 	
-	spin_unlock_irqrestore(&wc->lock, flags);
-
 	if (ints & 0x10) 
 		printk("PCI Master abort\n");
 



More information about the zaptel-commits mailing list