staging: comedi: add detachment counter for validity checks
authorIan Abbott <abbotti@mev.co.uk>
Fri, 8 Nov 2013 15:03:29 +0000 (15:03 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 12 Nov 2013 00:16:44 +0000 (16:16 -0800)
Add a member `detach_count` to `struct comedi_device` that is
incremented every time the device gets detached.  This will be used in
some validity checks in the 'read' and 'write' file operations to make
sure the attachment remains valid.

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

index 70de3558c74eb6dad4581a26430a96c49ae16095..05cc8dbcd515f513f06e6ad74fdb45b2f962fb65 100644 (file)
@@ -173,6 +173,7 @@ struct comedi_device {
 
        struct device *class_dev;
        int minor;
+       unsigned int detach_count;
        /* hw_dev is passed to dma_alloc_coherent when allocating async buffers
         * for subdevices that have async_dma_dir set to something other than
         * DMA_NONE */
index 4f727731a72d35ceabfc9a5107fc1ec651fc1a16..15b1ab885e77767efdf96d9f7c8b2010959d0de8 100644 (file)
@@ -136,6 +136,7 @@ void comedi_device_detach(struct comedi_device *dev)
        comedi_device_cancel_all(dev);
        down_write(&dev->attach_lock);
        dev->attached = false;
+       dev->detach_count++;
        if (dev->driver)
                dev->driver->detach(dev);
        comedi_device_detach_cleanup(dev);