staging: comedi: use refcount in comedi_driver_unregister()
authorIan Abbott <abbotti@mev.co.uk>
Fri, 8 Nov 2013 15:03:35 +0000 (15:03 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 12 Nov 2013 00:16:44 +0000 (16:16 -0800)
Change `comedi_driver_unregister()` to call
`comedi_dev_get_from_minor()` instead of `comedi_dev_from_minor()` when
finding devices using the driver.  This increments the reference count
to prevent the device being removed while it is being checked to see if
it is attached to the driver.  Call `comedi_dev_put()` to decrement the
reference afterwards.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers.c

index 15b1ab885e77767efdf96d9f7c8b2010959d0de8..a5d03b9c3717c99b3fbaa5265981479f1a56ed5f 100644 (file)
@@ -662,7 +662,7 @@ void comedi_driver_unregister(struct comedi_driver *driver)
 
        /* check for devices using this driver */
        for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) {
-               struct comedi_device *dev = comedi_dev_from_minor(i);
+               struct comedi_device *dev = comedi_dev_get_from_minor(i);
 
                if (!dev)
                        continue;
@@ -676,6 +676,7 @@ void comedi_driver_unregister(struct comedi_driver *driver)
                        comedi_device_detach(dev);
                }
                mutex_unlock(&dev->mutex);
+               comedi_dev_put(dev);
        }
 }
 EXPORT_SYMBOL_GPL(comedi_driver_unregister);