[zaptel-commits] tilghman: branch 1.2 r1468 - /branches/1.2/zaptel.c

zaptel-commits at lists.digium.com zaptel-commits at lists.digium.com
Sat Sep 16 00:45:05 MST 2006


Author: tilghman
Date: Sat Sep 16 02:45:04 2006
New Revision: 1468

URL: http://svn.digium.com/view/zaptel?rev=1468&view=rev
Log:
Round two of the fix for "hard-safe -> hard-unsafe lock order detected" (Issue 7620)
Only difference is that the fix is only defined for kernel versions 2.6.11 and
above; older kernels keep the current (possible deadlocking) code.

Modified:
    branches/1.2/zaptel.c

Modified: branches/1.2/zaptel.c
URL: http://svn.digium.com/view/zaptel/branches/1.2/zaptel.c?rev=1468&r1=1467&r2=1468&view=diff
==============================================================================
--- branches/1.2/zaptel.c (original)
+++ branches/1.2/zaptel.c Sat Sep 16 02:45:04 2006
@@ -1091,8 +1091,21 @@
 	/* Assumes channel is already locked */
 	if ((zone >= ZT_TONE_ZONE_MAX) || (zone < -1))
 		return -EINVAL;
-	
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11)
+	/* Since this routine is called both from IRQ as well as from userspace,
+	 * it is possible that we could be called during an IRQ while userspace
+	 * has locked this.  However unlikely, this could possibly cause a
+	 * deadlock. */
+	if (! read_trylock(&zone_lock))
+		return -EWOULDBLOCK;
+#else
+	/* But there are no trylock macros for kernel versions before 2.6.11,
+	 * so we do the unsafe thing anyway.  Such is the problem for dealing
+	 * with old, buggy kernels. */
 	read_lock(&zone_lock);
+#endif
+
 	if (zone == -1) {
 		zone = default_zone;
 	}
@@ -1103,7 +1116,7 @@
 	} else {
 		res = -ENODATA;
 	}
-	
+
 	read_unlock(&zone_lock);
 	return res;
 }



More information about the zaptel-commits mailing list