[PATCH 11/22] staging: comedi: addi_apci_3120: prevent deadlock in apci3120_ao_insn_write()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The DA_READY bit (0x0001) in the status register needs to be set before the
analog outputs can be updated.

Use comedi_timeout() to prevent a deadlock condition while waiting for the
DA_READY bit to get set.

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 .../comedi/drivers/addi-data/hwdrv_apci3120.c       | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c
index 0ba4b79..b6c11fe 100644
--- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c
+++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c
@@ -1923,21 +1923,34 @@ static int apci3120_do_insn_bits(struct comedi_device *dev,
 	return insn->n;
 }
 
+static int apci3120_ao_ready(struct comedi_device *dev,
+			     struct comedi_subdevice *s,
+			     struct comedi_insn *insn,
+			     unsigned long context)
+{
+	unsigned int status;
+
+	status = inw(dev->iobase + APCI3120_RD_STATUS);
+	if (status & 0x0001)	/* waiting for DA_READY */
+		return 0;
+	return -EBUSY;
+}
+
 static int apci3120_ao_insn_write(struct comedi_device *dev,
 				  struct comedi_subdevice *s,
 				  struct comedi_insn *insn,
 				  unsigned int *data)
 {
 	unsigned int ui_Channel;
-	unsigned short us_TmpValue;
+	int ret;
 
 	ui_Channel = CR_CHAN(insn->chanspec);
 
 	data[0] = ((((ui_Channel & 0x03) << 14) & 0xC000) | data[0]);
 
-	do {			/* Waiting of DA_READY BIT */
-		us_TmpValue = inw(dev->iobase + APCI3120_RD_STATUS) & 0x0001;
-	} while (us_TmpValue != 0x0001);
+	ret = comedi_timeout(dev, s, insn, apci3120_ao_ready, 0);
+	if (ret)
+		return ret;
 
 	if (ui_Channel <= 3)
 		/*
-- 
2.0.3

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux