From: H Hartley Sweeten Date: Thu, 21 Apr 2016 19:04:41 +0000 (-0700) Subject: staging: comedi: ni_mio_common: fix interrupt handler for dev->read_subdev X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=ba5c0da886c5f75f3bf7cab2f1f23a9ba05e04a5;p=linux-beck.git staging: comedi: ni_mio_common: fix interrupt handler for dev->read_subdev There may not be a dev->read_subdev, i.e. an analog input subdevice, that supports async commands. If it doesn't exist the interrupt/dma will never be enabled. Fix ni_E_interrupt() so that the analog input subdevice is only handled if it exists. This also fixes minor NULL dereference issue in handle_a_interrupt(). If the dev->read_subdev is NULL the comedi_async pointer (s->async) will not be allocated by the device postconfig so there is no way to get a valid comedi_cmd (&s->async->cmd). Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c b/drivers/staging/comedi/drivers/ni_mio_common.c index 1f661f2f399f..6e76c95a1e5c 100644 --- a/drivers/staging/comedi/drivers/ni_mio_common.c +++ b/drivers/staging/comedi/drivers/ni_mio_common.c @@ -1288,19 +1288,13 @@ static void ack_a_interrupt(struct comedi_device *dev, unsigned short a_status) ni_stc_writew(dev, ack, NISTC_INTA_ACK_REG); } -static void handle_a_interrupt(struct comedi_device *dev, unsigned short status, +static void handle_a_interrupt(struct comedi_device *dev, + struct comedi_subdevice *s, + unsigned short status, unsigned int ai_mite_status) { - struct comedi_subdevice *s = dev->read_subdev; struct comedi_cmd *cmd = &s->async->cmd; - /* - * 67xx boards don't have ai subdevice, but their gpct0 might - * generate an a interrupt. - */ - if (s->type == COMEDI_SUBD_UNUSED) - return; - #ifdef PCIDMA if (ai_mite_status & CHSR_LINKC) ni_sync_ai_dma(dev); @@ -5148,6 +5142,7 @@ static int ni_gpct_cancel(struct comedi_device *dev, struct comedi_subdevice *s) static irqreturn_t ni_E_interrupt(int irq, void *d) { struct comedi_device *dev = d; + struct comedi_subdevice *s_ai = dev->read_subdev; struct comedi_subdevice *s_ao = dev->write_subdev; unsigned short a_status; unsigned short b_status; @@ -5171,9 +5166,9 @@ static irqreturn_t ni_E_interrupt(int irq, void *d) unsigned int m_status; spin_lock_irqsave(&devpriv->mite_channel_lock, flags_too); - if (devpriv->ai_mite_chan) + if (s_ai && devpriv->ai_mite_chan) ai_mite_status = mite_ack_linkc(devpriv->ai_mite_chan, - dev->read_subdev); + s_ai); if (s_ao && devpriv->ao_mite_chan) { m_status = mite_ack_linkc(devpriv->ao_mite_chan, s_ao); @@ -5186,8 +5181,9 @@ static irqreturn_t ni_E_interrupt(int irq, void *d) #endif ack_a_interrupt(dev, a_status); ack_b_interrupt(dev, b_status); - if ((a_status & NISTC_AI_STATUS1_INTA) || (ai_mite_status & CHSR_INT)) - handle_a_interrupt(dev, a_status, ai_mite_status); + if (s_ai && + ((a_status & NISTC_AI_STATUS1_INTA) || (ai_mite_status & CHSR_INT))) + handle_a_interrupt(dev, s_ai, a_status, ai_mite_status); if (s_ao) { if (b_status & NISTC_AO_STATUS1_INTB) handle_b_interrupt(dev, s_ao, b_status);