dahdi: A little cleanup in the dahdi_ioctl_iomux function.
The primary change is to make clear that the wait result is not ever to be returned by the function. There are also edits to remove some comments that were expressed clearly in the source already and ensure that the iomux member of 'struct dahdi_chan' is only accessed under the chan->lock. Signed-off-by: Shaun Ruffell <sruffell@digium.com> Signed-off-by: Sean Bright <sean.bright@gmail.com> git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@9497 a0bf4364-ded3-4de4-8d8a-66a801d63aff
This commit is contained in:
parent
f406bba4c6
commit
75c33ce64e
@ -4981,70 +4981,62 @@ static int dahdi_ioctl_iomux(struct file *file, unsigned long data)
|
||||
{
|
||||
struct dahdi_chan *const chan = chan_from_file(file);
|
||||
unsigned long flags;
|
||||
int ret;
|
||||
unsigned int iomask;
|
||||
DEFINE_WAIT(wait);
|
||||
|
||||
if (!chan)
|
||||
return -EINVAL;
|
||||
if (get_user(iomask, (int __user *)data))
|
||||
return -EFAULT;
|
||||
|
||||
get_user(chan->iomask, (int __user *)data);
|
||||
if (!chan->iomask)
|
||||
if (unlikely(!iomask || !chan))
|
||||
return -EINVAL;
|
||||
|
||||
while (1) {
|
||||
unsigned int wait_result;
|
||||
|
||||
ret = 0;
|
||||
wait_result = 0;
|
||||
prepare_to_wait(&chan->eventbufq, &wait, TASK_INTERRUPTIBLE);
|
||||
|
||||
spin_lock_irqsave(&chan->lock, flags);
|
||||
/* if looking for read */
|
||||
if (chan->iomask & DAHDI_IOMUX_READ) {
|
||||
/* if read available */
|
||||
chan->iomask = iomask;
|
||||
if (iomask & DAHDI_IOMUX_READ) {
|
||||
if ((chan->outreadbuf > -1) && !chan->rxdisable)
|
||||
ret |= DAHDI_IOMUX_READ;
|
||||
wait_result |= DAHDI_IOMUX_READ;
|
||||
}
|
||||
|
||||
/* if looking for write avail */
|
||||
if (chan->iomask & DAHDI_IOMUX_WRITE) {
|
||||
if (iomask & DAHDI_IOMUX_WRITE) {
|
||||
if (chan->inwritebuf > -1)
|
||||
ret |= DAHDI_IOMUX_WRITE;
|
||||
wait_result |= DAHDI_IOMUX_WRITE;
|
||||
}
|
||||
/* if looking for write empty */
|
||||
if (chan->iomask & DAHDI_IOMUX_WRITEEMPTY) {
|
||||
if (iomask & DAHDI_IOMUX_WRITEEMPTY) {
|
||||
/* if everything empty -- be sure the transmitter is
|
||||
* enabled */
|
||||
chan->txdisable = 0;
|
||||
if (chan->outwritebuf < 0)
|
||||
ret |= DAHDI_IOMUX_WRITEEMPTY;
|
||||
wait_result |= DAHDI_IOMUX_WRITEEMPTY;
|
||||
}
|
||||
/* if looking for signalling event */
|
||||
if (chan->iomask & DAHDI_IOMUX_SIGEVENT) {
|
||||
/* if event */
|
||||
if (iomask & DAHDI_IOMUX_SIGEVENT) {
|
||||
if (chan->eventinidx != chan->eventoutidx)
|
||||
ret |= DAHDI_IOMUX_SIGEVENT;
|
||||
wait_result |= DAHDI_IOMUX_SIGEVENT;
|
||||
}
|
||||
spin_unlock_irqrestore(&chan->lock, flags);
|
||||
|
||||
/* if something to return, or not to wait */
|
||||
if (ret || (chan->iomask & DAHDI_IOMUX_NOWAIT)) {
|
||||
/* set return value */
|
||||
put_user(ret, (int __user *)data);
|
||||
ret = 0;
|
||||
break; /* get out of loop */
|
||||
}
|
||||
|
||||
if (!signal_pending(current)) {
|
||||
schedule();
|
||||
continue;
|
||||
}
|
||||
|
||||
ret = -ERESTARTSYS;
|
||||
if (wait_result || (iomask & DAHDI_IOMUX_NOWAIT)) {
|
||||
put_user(wait_result, (int __user *)data);
|
||||
break;
|
||||
}
|
||||
|
||||
if (signal_pending(current)) {
|
||||
finish_wait(&chan->eventbufq, &wait);
|
||||
return -ERESTARTSYS;
|
||||
}
|
||||
|
||||
schedule();
|
||||
}
|
||||
|
||||
finish_wait(&chan->eventbufq, &wait);
|
||||
spin_lock_irqsave(&chan->lock, flags);
|
||||
chan->iomask = 0;
|
||||
return ret;
|
||||
spin_unlock_irqrestore(&chan->lock, flags);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_DAHDI_MIRROR
|
||||
|
@ -509,7 +509,7 @@ struct dahdi_chan {
|
||||
int cadencepos; /*!< Where in the cadence we are */
|
||||
|
||||
/* I/O Mask */
|
||||
int iomask; /*! I/O Mux signal mask */
|
||||
unsigned int iomask; /*! I/O Mux signal mask */
|
||||
wait_queue_head_t sel; /*! thingy for select stuff */
|
||||
|
||||
/* HDLC state machines */
|
||||
|
Loading…
Reference in New Issue
Block a user