summaryrefslogtreecommitdiff
path: root/zaptel.c
diff options
context:
space:
mode:
authortilghman <tilghman@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2006-09-16 07:48:33 +0000
committertilghman <tilghman@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2006-09-16 07:48:33 +0000
commit49a8ddcaa2daae8a19765443cd124c043c96074c (patch)
treef8d1c1bb6f2c315449ccecf6aecf9681865f7083 /zaptel.c
parent721dda88d1b4eb929ee867143aa963b31cfd8442 (diff)
Merged revisions 1468 via svnmerge from
https://origsvn.digium.com/svn/zaptel/branches/1.2 ........ r1468 | tilghman | 2006-09-16 02:45:04 -0500 (Sat, 16 Sep 2006) | 4 lines 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. ........ git-svn-id: http://svn.digium.com/svn/zaptel/trunk@1469 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'zaptel.c')
-rw-r--r--zaptel.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/zaptel.c b/zaptel.c
index bf561ff..df920de 100644
--- a/zaptel.c
+++ b/zaptel.c
@@ -1154,8 +1154,21 @@ static int set_tone_zone(struct zt_chan *chan, int zone)
/* 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;
}
@@ -1166,7 +1179,7 @@ static int set_tone_zone(struct zt_chan *chan, int zone)
} else {
res = -ENODATA;
}
-
+
read_unlock(&zone_lock);
return res;
}