[zaptel-commits] russell: tag 1.4.9.2 r3911 - /tags/1.4.9.2/kernel/zaptel-base.c

SVN commits to the Zaptel project zaptel-commits at lists.digium.com
Thu Feb 28 13:00:48 CST 2008


Author: russell
Date: Thu Feb 28 13:00:47 2008
New Revision: 3911

URL: http://svn.digium.com/view/zaptel?view=rev&rev=3911
Log:
Apply rev 3885 from branches/1.4 to fix a crash related to default zone handling

Modified:
    tags/1.4.9.2/kernel/zaptel-base.c

Modified: tags/1.4.9.2/kernel/zaptel-base.c
URL: http://svn.digium.com/view/zaptel/tags/1.4.9.2/kernel/zaptel-base.c?view=diff&rev=3911&r1=3910&r2=3911
==============================================================================
--- tags/1.4.9.2/kernel/zaptel-base.c (original)
+++ tags/1.4.9.2/kernel/zaptel-base.c Thu Feb 28 13:00:47 2008
@@ -2590,6 +2590,23 @@
 	
 }
 
+static int zt_set_default_zone(int defzone)
+{
+	if ((defzone < 0) || (defzone >= ZT_TONE_ZONE_MAX))
+		return -EINVAL;
+	write_lock(&zone_lock);
+	if (!tone_zones[defzone]) {
+		write_unlock(&zone_lock);
+		return -EINVAL;
+	}
+	if ((default_zone != -1) && tone_zones[default_zone])
+		atomic_dec(&tone_zones[default_zone]->refcount);
+	atomic_inc(&tone_zones[defzone]->refcount);
+	default_zone = defzone;
+	write_unlock(&zone_lock);
+	return 0;
+}
+
 /* No bigger than 32k for everything per tone zone */
 #define MAX_SIZE 32768
 /* No more than 128 subtones */
@@ -2737,8 +2754,13 @@
 			samples[x]->next = samples[next[x]];
 	}
 
-	if ((res = zt_register_tone_zone(th.zone, z)))
+	if ((res = zt_register_tone_zone(th.zone, z))) {
 		kfree(slab);
+	} else {
+		if ( -1 == default_zone ) {
+			zt_set_default_zone(th.zone);
+		}
+	}
 
 	return res;
 }
@@ -3664,19 +3686,7 @@
 	case ZT_DEFAULTZONE:
 		if (get_user(j,(int *)data))
 			return -EFAULT;
-		if ((j < 0) || (j >= ZT_TONE_ZONE_MAX))
-			return -EINVAL;
-		write_lock(&zone_lock);
-		if (!tone_zones[j]) {
-			write_unlock(&zone_lock);
-			return -EINVAL;
-		}
-		if ((default_zone != -1) && tone_zones[default_zone])
-			atomic_dec(&tone_zones[default_zone]->refcount);
-		atomic_inc(&tone_zones[j]->refcount);
-		default_zone = j;
-		write_unlock(&zone_lock);
-		break;
+		return zt_set_default_zone(j);
 	case ZT_LOADZONE:
 		return ioctl_load_zone(data);
 	case ZT_FREEZONE:




More information about the zaptel-commits mailing list