Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ba5c0da8 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman
Browse files

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: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 4b2d7389
Loading
Loading
Loading
Loading
+9 −13
Original line number Diff line number Diff line
@@ -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);