Put the hardware into a safe state before enabling the interrupt.  In
the interrupt routine, check the device has been fully configured by
checking `dev->attached`.  In particular, `dev->read_subdev` could be
NULL early on and although the hardware's status register should
indicate no interrupt has occurred (since it's been put into a safe
state), it's better not to rely on it.
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
        struct comedi_subdevice *s = dev->read_subdev;
        unsigned int val;
 
+       if (!dev->attached)
+               return IRQ_NONE;
+
        /* Check if VCC OR CC interrupt has occurred */
        val = inl(dev->iobase + APCI2032_STATUS_REG) & APCI2032_STATUS_IRQ;
        if (!val)
        if (ret)
                return ret;
        dev->iobase = pci_resource_start(pcidev, 1);
+       apci2032_reset(dev);
 
        if (pcidev->irq > 0) {
                ret = request_irq(pcidev->irq, apci2032_interrupt,
                s->type         = COMEDI_SUBD_UNUSED;
        }
 
-       apci2032_reset(dev);
        return 0;
 }