Do the request_irq() before setting up the subdevices. Only hook up the command support of the irq was sucessfully requested. Note that, because of the IRQF_SHARED flag, nidio_interrupt() _may_ be called before the device is ready and the subdevices are setup. This condition is handled by the (!dev->attached) sanity check. The 'dev->read_subdev' pointer might not be valid at this point so there is an extra check to get the pointer to the comedi_async buffer. Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx> Cc: Ian Abbott <abbotti@xxxxxxxxx> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- v3: fix a possible dereference of 's' in nido_interrupt() drivers/staging/comedi/drivers/ni_pcidio.c | 40 +++++++++++++++--------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/drivers/staging/comedi/drivers/ni_pcidio.c b/drivers/staging/comedi/drivers/ni_pcidio.c index 30c46a3..8f1b64d 100644 --- a/drivers/staging/comedi/drivers/ni_pcidio.c +++ b/drivers/staging/comedi/drivers/ni_pcidio.c @@ -385,7 +385,7 @@ static irqreturn_t nidio_interrupt(int irq, void *d) struct comedi_device *dev = d; struct nidio96_private *devpriv = dev->private; struct comedi_subdevice *s = dev->read_subdev; - struct comedi_async *async = s->async; + struct comedi_async *async = s ? s->async : NULL; struct mite_struct *mite = devpriv->mite; /* int i, j; */ @@ -1011,6 +1011,14 @@ static int nidio_auto_attach(struct comedi_device *dev, nidio_reset_board(dev); + irq = mite_irq(devpriv->mite); + if (irq) { + ret = request_irq(irq, nidio_interrupt, IRQF_SHARED, + dev->board_name, dev); + if (ret == 0) + dev->irq = irq; + } + ret = comedi_alloc_subdevices(dev, 1); if (ret) return ret; @@ -1019,31 +1027,23 @@ static int nidio_auto_attach(struct comedi_device *dev, readb(devpriv->mite->daq_io_addr + Chip_Version)); s = &dev->subdevices[0]; - - dev->read_subdev = s; s->type = COMEDI_SUBD_DIO; - s->subdev_flags = - SDF_READABLE | SDF_WRITABLE | SDF_LSAMPL | SDF_PACKED | - SDF_CMD_READ; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_LSAMPL | SDF_PACKED; s->n_chan = 32; s->range_table = &range_digital; s->maxdata = 1; s->insn_config = &ni_pcidio_insn_config; s->insn_bits = &ni_pcidio_insn_bits; - s->do_cmd = &ni_pcidio_cmd; - s->do_cmdtest = &ni_pcidio_cmdtest; - s->cancel = &ni_pcidio_cancel; - s->len_chanlist = 32; /* XXX */ - s->buf_change = &ni_pcidio_change; - s->async_dma_dir = DMA_BIDIRECTIONAL; - s->poll = &ni_pcidio_poll; - - irq = mite_irq(devpriv->mite); - if (irq) { - ret = request_irq(irq, nidio_interrupt, IRQF_SHARED, - dev->board_name, dev); - if (ret == 0) - dev->irq = irq; + if (dev->irq) { + dev->read_subdev = s; + s->subdev_flags |= SDF_CMD_READ; + s->async_dma_dir = DMA_BIDIRECTIONAL; + s->len_chanlist = s->n_chan; + s->do_cmd = ni_pcidio_cmd; + s->do_cmdtest = ni_pcidio_cmdtest; + s->cancel = ni_pcidio_cancel; + s->poll = ni_pcidio_poll; + s->buf_change = ni_pcidio_change; } return 0; -- 1.8.4.4 _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel