Staging: comedi: convert while loop to timeout in ni_mio_common.c
authorChase Southwood <chase.southwood@yahoo.com>
Thu, 16 Jan 2014 18:27:29 +0000 (12:27 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 7 Feb 2014 18:02:05 +0000 (10:02 -0800)
This patch for ni_mio_common.c changes out a while loop for a timeout,
which is preferred.

Signed-off-by: Chase Southwood <chase.southwood@yahoo.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/ni_mio_common.c

index 457b88481db0a9b4c6fde73fceef556dc66b8278..10c27cb278cbb28e49f2d651b19b738e02467a2c 100644 (file)
@@ -687,12 +687,22 @@ static void ni_clear_ai_fifo(struct comedi_device *dev)
 {
        const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
+       static const int timeout = 10000;
+       int i;
 
        if (board->reg_type == ni_reg_6143) {
                /*  Flush the 6143 data FIFO */
                ni_writel(0x10, AIFIFO_Control_6143);   /*  Flush fifo */
                ni_writel(0x00, AIFIFO_Control_6143);   /*  Flush fifo */
-               while (ni_readl(AIFIFO_Status_6143) & 0x10) ;   /*  Wait for complete */
+               /*  Wait for complete */
+               for (i = 0; i < timeout; i++) {
+                       if (!(ni_readl(AIFIFO_Status_6143) & 0x10))
+                               break;
+                       udelay(1);
+               }
+               if (i == timeout) {
+                       comedi_error(dev, "FIFO flush timeout.");
+               }
        } else {
                devpriv->stc_writew(dev, 1, ADC_FIFO_Clear);
                if (board->reg_type == ni_reg_625x) {