[svn-commits] sruffell: linux/trunk r9497 - in /linux/trunk: drivers/dahdi/ include/dahdi/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Nov 24 18:07:14 CST 2010


Author: sruffell
Date: Wed Nov 24 18:07:10 2010
New Revision: 9497

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=9497
Log:
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 at digium.com>
Signed-off-by: Sean Bright <sean.bright at gmail.com>

Modified:
    linux/trunk/drivers/dahdi/dahdi-base.c
    linux/trunk/include/dahdi/kernel.h

Modified: linux/trunk/drivers/dahdi/dahdi-base.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/dahdi-base.c?view=diff&rev=9497&r1=9496&r2=9497
==============================================================================
--- linux/trunk/drivers/dahdi/dahdi-base.c (original)
+++ linux/trunk/drivers/dahdi/dahdi-base.c Wed Nov 24 18:07:10 2010
@@ -4981,70 +4981,62 @@
 {
 	struct dahdi_chan *const chan = chan_from_file(file);
 	unsigned long flags;
-	int ret;
+	unsigned int iomask;
 	DEFINE_WAIT(wait);
 
-	if (!chan)
+	if (get_user(iomask, (int __user *)data))
+		return -EFAULT;
+
+	if (unlikely(!iomask || !chan))
 		return -EINVAL;
 
-	get_user(chan->iomask, (int __user *)data);
-	if (!chan->iomask)
-		return -EINVAL;
-
 	while (1) {
-
-		ret = 0;
+		unsigned int wait_result;
+
+		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;
-		}
-
-		/* if looking for write avail */
-		if (chan->iomask & DAHDI_IOMUX_WRITE) {
+				wait_result |= DAHDI_IOMUX_READ;
+		}
+		if (iomask & DAHDI_IOMUX_WRITE) {
 			if (chan->inwritebuf > -1)
-				ret |= DAHDI_IOMUX_WRITE;
-		}
-		/* if looking for write empty */
-		if (chan->iomask & DAHDI_IOMUX_WRITEEMPTY) {
+				wait_result |= DAHDI_IOMUX_WRITE;
+		}
+		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;
-		}
-		/* if looking for signalling event */
-		if (chan->iomask & DAHDI_IOMUX_SIGEVENT) {
-			/* if event */
+				wait_result |= DAHDI_IOMUX_WRITEEMPTY;
+		}
+		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;
-		break;
+		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

Modified: linux/trunk/include/dahdi/kernel.h
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/include/dahdi/kernel.h?view=diff&rev=9497&r1=9496&r2=9497
==============================================================================
--- linux/trunk/include/dahdi/kernel.h (original)
+++ linux/trunk/include/dahdi/kernel.h Wed Nov 24 18:07:10 2010
@@ -509,7 +509,7 @@
 	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 */




More information about the svn-commits mailing list