[zaptel-commits] mattf: branch mattf/zaptel-1.4-stackcleanup r4092 - /team/mattf/zaptel-1.4-st...

SVN commits to the Zaptel project zaptel-commits at lists.digium.com
Wed Mar 26 14:37:43 CDT 2008


Author: mattf
Date: Wed Mar 26 14:37:43 2008
New Revision: 4092

URL: http://svn.digium.com/view/zaptel?view=rev&rev=4092
Log:
Reduce stack in zt_chanandpseudo_ioctl by ~256 bytes and cleanup one of the ioctl calls

Modified:
    team/mattf/zaptel-1.4-stackcleanup/kernel/zaptel-base.c

Modified: team/mattf/zaptel-1.4-stackcleanup/kernel/zaptel-base.c
URL: http://svn.digium.com/view/zaptel/team/mattf/zaptel-1.4-stackcleanup/kernel/zaptel-base.c?view=diff&rev=4092&r1=4091&r2=4092
==============================================================================
--- team/mattf/zaptel-1.4-stackcleanup/kernel/zaptel-base.c (original)
+++ team/mattf/zaptel-1.4-stackcleanup/kernel/zaptel-base.c Wed Mar 26 14:37:43 2008
@@ -3948,11 +3948,62 @@
 	return 0;
 }
 
+static int ioctl_zt_dial(struct zt_chan *chan, unsigned long data)
+{
+	struct zt_dialoperation *tdo;
+	unsigned long flags;
+	char *s;
+	int rv;
+
+	tdo = kmalloc(sizeof(*tdo), GFP_KERNEL);
+
+	if (!tdo)
+		return -ENOMEM;
+
+	if (copy_from_user(tdo, (struct zt_dialoperation *)data, sizeof(*tdo)))
+		return -EFAULT;
+	rv = 0;
+	/* Force proper NULL termination and uppercase entry */
+	tdo->dialstr[ZT_MAX_DTMF_BUF - 1] = '\0';
+	for (s = tdo->dialstr; *s; s++)
+		*s = toupper(*s);
+	spin_lock_irqsave(&chan->lock, flags);
+	switch (tdo->op) {
+	case ZT_DIAL_OP_CANCEL:
+		chan->curtone = NULL;
+		chan->dialing = 0;
+		chan->txdialbuf[0] = '\0';
+		chan->tonep = 0;
+		chan->pdialcount = 0;
+		break;
+	case ZT_DIAL_OP_REPLACE:
+		strcpy(chan->txdialbuf, tdo->dialstr);
+		chan->dialing = 1;
+		__do_dtmf(chan);
+		break;
+	case ZT_DIAL_OP_APPEND:
+		if (strlen(tdo->dialstr) + strlen(chan->txdialbuf) >= (ZT_MAX_DTMF_BUF - 1)) {
+			rv = -EBUSY;
+			break;
+		}
+		zap_copy_string(chan->txdialbuf + strlen(chan->txdialbuf), tdo->dialstr, ZT_MAX_DTMF_BUF - strlen(chan->txdialbuf));
+		if (!chan->dialing) {
+			chan->dialing = 1;
+			__do_dtmf(chan);
+		}
+		break;
+	default:
+		rv = -EINVAL;
+	}
+	spin_unlock_irqrestore(&chan->lock, flags);
+
+	return rv;
+}
+
 static int zt_chanandpseudo_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long data, int unit)
 {
 	struct zt_chan *chan = chans[unit];
 	union {
-		struct zt_dialoperation tdo;
 		struct zt_bufferinfo bi;
 		struct zt_confinfo conf;
 		struct zt_ring_cadence cad;
@@ -3960,7 +4011,6 @@
 	unsigned long flags, flagso;
 	int i, j, k, rv;
 	int ret, c;
-	char *s;
 	
 	if (!chan)
 		return -EINVAL;
@@ -3973,43 +4023,7 @@
 			return -EFAULT;
 		return 0;
 	case ZT_DIAL:
-		if (copy_from_user(&stack.tdo, (struct zt_dialoperation *)data, sizeof(stack.tdo)))
-			return -EFAULT;
-		rv = 0;
-		/* Force proper NULL termination and uppercase entry */
-		stack.tdo.dialstr[ZT_MAX_DTMF_BUF - 1] = '\0';
-		for (s = stack.tdo.dialstr; *s; s++)
-			*s = toupper(*s);
-		spin_lock_irqsave(&chan->lock, flags);
-		switch (stack.tdo.op) {
-		case ZT_DIAL_OP_CANCEL:
-			chan->curtone = NULL;
-			chan->dialing = 0;
-			chan->txdialbuf[0] = '\0';
-			chan->tonep = 0;
-			chan->pdialcount = 0;
-			break;
-		case ZT_DIAL_OP_REPLACE:
-			strcpy(chan->txdialbuf, stack.tdo.dialstr);
-			chan->dialing = 1;
-			__do_dtmf(chan);
-			break;
-		case ZT_DIAL_OP_APPEND:
-			if (strlen(stack.tdo.dialstr) + strlen(chan->txdialbuf) >= (ZT_MAX_DTMF_BUF - 1)) {
-				rv = -EBUSY;
-				break;
-			}
-			zap_copy_string(chan->txdialbuf + strlen(chan->txdialbuf), stack.tdo.dialstr, ZT_MAX_DTMF_BUF - strlen(chan->txdialbuf));
-			if (!chan->dialing) {
-				chan->dialing = 1;
-				__do_dtmf(chan);
-			}
-			break;
-		default:
-			rv = -EINVAL;
-		}
-		spin_unlock_irqrestore(&chan->lock, flags);
-		return rv;
+		return ioctl_zt_dial(chan, data);
 	case ZT_GET_BUFINFO:
 		stack.bi.rxbufpolicy = chan->rxbufpolicy;
 		stack.bi.txbufpolicy = chan->txbufpolicy;
@@ -4537,6 +4551,9 @@
 		return -EINVAL;
 	
 	params = kmalloc(sizeof(params[0]) * ZT_MAX_ECHOCANPARAMS, GFP_KERNEL);
+	
+	if (!params)
+		return -ENOMEM;
 
 	/* enable mode, need the params */
 	




More information about the zaptel-commits mailing list