staging: comedi: pcmuio: fix possible NULL deref on detach
authorIan Abbott <abbotti@mev.co.uk>
Tue, 20 Aug 2013 10:50:19 +0000 (11:50 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 22 Aug 2013 17:07:49 +0000 (10:07 -0700)
pcmuio_detach() is called by the comedi core even if pcmuio_attach()
returned an error, so `dev->private` might be `NULL`.  Check for that
before dereferencing it.

Also, as pointed out by Dan Carpenter, there is no need to check the
pointer passed to `kfree()` is non-NULL, so remove that check.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/pcmuio.c

index f942455..67e2bb1 100644 (file)
@@ -672,12 +672,13 @@ static void pcmuio_detach(struct comedi_device *dev)
        struct pcmuio_private *devpriv = dev->private;
        int i;
 
-       for (i = 0; i < PCMUIO_MAX_ASICS; ++i) {
-               if (devpriv->asics[i].irq)
-                       free_irq(devpriv->asics[i].irq, dev);
-       }
-       if (devpriv && devpriv->sprivs)
+       if (devpriv) {
+               for (i = 0; i < PCMUIO_MAX_ASICS; ++i) {
+                       if (devpriv->asics[i].irq)
+                               free_irq(devpriv->asics[i].irq, dev);
+               }
                kfree(devpriv->sprivs);
+       }
        comedi_legacy_detach(dev);
 }