From 6e42b175c8c81c84bbe09aa7c4c51b9a3522fcfe Mon Sep 17 00:00:00 2001 From: mattf Date: Sat, 7 Apr 2007 16:49:46 +0000 Subject: Fix for #9208. Thanks adomo and Tzafrir! git-svn-id: http://svn.digium.com/svn/zaptel/branches/1.2@2398 5390a7c7-147a-4af0-8ec9-7488f05a26cb --- zaptel-base.c | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) (limited to 'zaptel-base.c') diff --git a/zaptel-base.c b/zaptel-base.c index db9b90e..842a145 100644 --- a/zaptel-base.c +++ b/zaptel-base.c @@ -748,16 +748,19 @@ static int schluffen(wait_queue_head_t *q) if (!signal_pending(current)) schedule(); current->state = TASK_RUNNING; remove_wait_queue(q, &wait); - if (signal_pending(current)) return -ERESTARTSYS; + if (signal_pending(current)) { + printk(KERN_WARNING "zaptel.c:%d (pid %d: %s) got signal %08lX\n", __LINE__, current->pid, current->comm, current->pending.signal.sig[0]); + return -ERESTARTSYS; + } return(0); } -static inline void calc_fcs(struct zt_chan *ss) +static inline void calc_fcs(struct zt_chan *ss, int inwritebuf) { int x; unsigned int fcs=PPP_INITFCS; - unsigned char *data = ss->writebuf[ss->inwritebuf]; - int len = ss->writen[ss->inwritebuf]; + unsigned char *data = ss->writebuf[inwritebuf]; + int len = ss->writen[inwritebuf]; /* Not enough space to do FCS calculation */ if (len < 2) return; @@ -1692,8 +1695,8 @@ static ssize_t zt_chan_read(struct file *file, char *usrbuf, size_t count, int u } amnt = count; if (chan->flags & ZT_FLAG_LINEAR) { - if (amnt > (chan->readn[chan->outreadbuf] << 1)) - amnt = chan->readn[chan->outreadbuf] << 1; + if (amnt > (chan->readn[res] << 1)) + amnt = chan->readn[res] << 1; if (amnt) { /* There seems to be a max stack size, so we have to do this in smaller pieces */ @@ -1706,7 +1709,7 @@ static ssize_t zt_chan_read(struct file *file, char *usrbuf, size_t count, int u if (pass > 128) pass = 128; for (x=0;xreadbuf[chan->outreadbuf][x + pos], chan); + lindata[x] = ZT_XLAW(chan->readbuf[res][x + pos], chan); if (copy_to_user(usrbuf + (pos << 1), lindata, pass << 1)) return -EFAULT; left -= pass; @@ -1714,18 +1717,18 @@ static ssize_t zt_chan_read(struct file *file, char *usrbuf, size_t count, int u } } } else { - if (amnt > chan->readn[chan->outreadbuf]) - amnt = chan->readn[chan->outreadbuf]; + if (amnt > chan->readn[res]) + amnt = chan->readn[res]; if (amnt) { - if (copy_to_user(usrbuf, chan->readbuf[chan->outreadbuf], amnt)) + if (copy_to_user(usrbuf, chan->readbuf[res], amnt)) return -EFAULT; } } spin_lock_irqsave(&chan->lock, flags); - chan->readidx[chan->outreadbuf] = 0; - chan->readn[chan->outreadbuf] = 0; - oldbuf = chan->outreadbuf; - chan->outreadbuf = (chan->outreadbuf + 1) % chan->numbufs; + chan->readidx[res] = 0; + chan->readn[res] = 0; + oldbuf = res; + res = (chan->outreadbuf + 1) % chan->numbufs; if (chan->outreadbuf == chan->inreadbuf) { /* Out of stuff */ chan->outreadbuf = -1; @@ -1807,21 +1810,21 @@ static ssize_t zt_chan_write(struct file *file, const char *usrbuf, size_t count return -EFAULT; left -= pass; for (x=0;xwritebuf[chan->inwritebuf][x + pos] = ZT_LIN2X(lindata[x], chan); + chan->writebuf[res][x + pos] = ZT_LIN2X(lindata[x], chan); pos += pass; } - chan->writen[chan->inwritebuf] = amnt >> 1; + chan->writen[res] = amnt >> 1; } else { - if (copy_from_user(chan->writebuf[chan->inwritebuf], usrbuf, amnt)) + if (copy_from_user(chan->writebuf[res], usrbuf, amnt)) return -EFAULT; - chan->writen[chan->inwritebuf] = amnt; + chan->writen[res] = amnt; } - chan->writeidx[chan->inwritebuf] = 0; + chan->writeidx[res] = 0; if (chan->flags & ZT_FLAG_FCS) - calc_fcs(chan); - oldbuf = chan->inwritebuf; + calc_fcs(chan, res); + oldbuf = res; spin_lock_irqsave(&chan->lock, flags); - chan->inwritebuf = (chan->inwritebuf + 1) % chan->numbufs; + chan->inwritebuf = (res + 1) % chan->numbufs; if (chan->inwritebuf == chan->outwritebuf) { /* Don't stomp on the transmitter, just wait for them to wake us up */ -- cgit v1.2.3