Re: [PATCH 18/51] staging: comedi: ni_at_a2150: tidy up the irq request

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

 



On 2013-12-03 19:07, H Hartley Sweeten wrote:
The irq is only needed to support async commands. Tidy up the
code that does the request_irq() and remove the noise.

Only hookup the subdevice command support if the irq is available.

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

diff --git a/drivers/staging/comedi/drivers/ni_at_a2150.c b/drivers/staging/comedi/drivers/ni_at_a2150.c
index cc69dde..8924fbd 100644
--- a/drivers/staging/comedi/drivers/ni_at_a2150.c
+++ b/drivers/staging/comedi/drivers/ni_at_a2150.c
@@ -689,7 +689,6 @@ static int a2150_attach(struct comedi_device *dev, struct comedi_devconfig *it)
  	const struct a2150_board *thisboard = comedi_board(dev);
  	struct a2150_private *devpriv;
  	struct comedi_subdevice *s;
-	unsigned int irq = it->options[1];
  	unsigned int dma = it->options[2];
  	static const int timeout = 2000;
  	int i;
@@ -703,21 +702,20 @@ static int a2150_attach(struct comedi_device *dev, struct comedi_devconfig *it)
  	if (ret)
  		return ret;

-	/* grab our IRQ */
-	if (irq) {
-		/*  check that irq is supported */
-		if (irq < 3 || irq == 8 || irq == 13 || irq > 15) {
-			printk(" invalid irq line %u\n", irq);
-			return -EINVAL;
-		}
-		if (request_irq(irq, a2150_interrupt, 0,
-				dev->driver->driver_name, dev)) {
-			printk("unable to allocate irq %u\n", irq);
-			return -EINVAL;
+	dev->board_ptr = a2150_boards + a2150_probe(dev);
+	thisboard = comedi_board(dev);
+	dev->board_name = thisboard->name;
+
+	/* only irqs 3, 4, 5, 6, 7, 9, 10, 11, 12, 14 and 15 are valid */
+	if ((1 << it->options[1]) & 0xdef8) {

This test result is undefined if it->options[1] is greater than or equal to 32, or less than 0. So you need to range check it as well. You might as well use the original test since it's easier to understand.

+		ret = request_irq(it->options[1], a2150_interrupt, 0,
+				  dev->board_name, dev);
+		if (ret == 0) {
+			dev->irq = it->options[1];
+			devpriv->irq_dma_bits |= IRQ_LVL_BITS(dev->irq);
  		}
-		devpriv->irq_dma_bits |= IRQ_LVL_BITS(irq);
-		dev->irq = irq;
  	}
+
  	/*  initialize dma */
  	if (dma) {
  		if (dma == 4 || dma > 7) {
@@ -740,27 +738,26 @@ static int a2150_attach(struct comedi_device *dev, struct comedi_devconfig *it)
  		devpriv->irq_dma_bits |= DMA_CHAN_BITS(dma);
  	}

-	dev->board_ptr = a2150_boards + a2150_probe(dev);
-	thisboard = comedi_board(dev);
-	dev->board_name = thisboard->name;
-
  	ret = comedi_alloc_subdevices(dev, 1);
  	if (ret)
  		return ret;

  	/* analog input subdevice */
  	s = &dev->subdevices[0];
-	dev->read_subdev = s;
  	s->type = COMEDI_SUBD_AI;
-	s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_OTHER | SDF_CMD_READ;
+	s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_OTHER;
  	s->n_chan = 4;
-	s->len_chanlist = 4;
  	s->maxdata = 0xffff;
  	s->range_table = &range_a2150;
-	s->do_cmd = a2150_ai_cmd;
-	s->do_cmdtest = a2150_ai_cmdtest;
  	s->insn_read = a2150_ai_rinsn;
-	s->cancel = a2150_cancel;
+	if (dev->irq) {
+		dev->read_subdev = s;
+		s->subdev_flags |= SDF_CMD_READ;
+		s->len_chanlist = 4;
+		s->do_cmd = a2150_ai_cmd;
+		s->do_cmdtest = a2150_ai_cmdtest;
+		s->cancel = a2150_cancel;
+	}

  	/* need to do this for software counting of completed conversions, to
  	 * prevent hardware count from stopping acquisition */



--
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti@xxxxxxxxx>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-
_______________________________________________
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