This function is intended to be used by the comedi legacy (ISA) drivers
either directly as the (*detach) function or as a helper in the drivers
private (*detach) function.

Modify the comedi_request_region() helper so that it stores the 'len' of
the region as well as the 'start' after the region has been successfuly
allocated by request_region() in __comedi_request_region(). This region
will then be automatically released detach of the driver by the
comedi_legacy_detach() helper.

Signed-off-by: H Hartley Sweeten <[email protected]>
Cc: Ian Abbott <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
---
 drivers/staging/comedi/comedidev.h |  2 ++
 drivers/staging/comedi/drivers.c   | 19 ++++++++++++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/comedidev.h 
b/drivers/staging/comedi/comedidev.h
index ce509d0..cdd4720 100644
--- a/drivers/staging/comedi/comedidev.h
+++ b/drivers/staging/comedi/comedidev.h
@@ -216,6 +216,7 @@ struct comedi_device {
 
        /* dumb */
        unsigned long iobase;
+       unsigned long iolen;
        unsigned int irq;
 
        struct comedi_subdevice *read_subdev;
@@ -354,6 +355,7 @@ int __comedi_request_region(struct comedi_device *,
                            unsigned long start, unsigned long len);
 int comedi_request_region(struct comedi_device *,
                          unsigned long start, unsigned long len);
+void comedi_legacy_detach(struct comedi_device *);
 
 int comedi_auto_config(struct device *, struct comedi_driver *,
                       unsigned long context);
diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index 2a28f64..6fecefe 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -122,6 +122,7 @@ static void cleanup_device(struct comedi_device *dev)
        dev->board_name = NULL;
        dev->board_ptr = NULL;
        dev->iobase = 0;
+       dev->iolen = 0;
        dev->ioenabled = false;
        dev->irq = 0;
        dev->read_subdev = NULL;
@@ -387,13 +388,29 @@ int comedi_request_region(struct comedi_device *dev,
        int ret;
 
        ret = __comedi_request_region(dev, start, len);
-       if (ret == 0)
+       if (ret == 0) {
                dev->iobase = start;
+               dev->iolen = len;
+       }
 
        return ret;
 }
 EXPORT_SYMBOL_GPL(comedi_request_region);
 
+/**
+ * comedi_legacy_detach() - A generic (*detach) function for legacy drivers.
+ * @dev: comedi_device struct
+ */
+void comedi_legacy_detach(struct comedi_device *dev)
+{
+       if (dev->iobase && dev->iolen) {
+               release_region(dev->iobase, dev->iolen);
+               dev->iobase = 0;
+               dev->iolen = 0;
+       }
+}
+EXPORT_SYMBOL_GPL(comedi_legacy_detach);
+
 int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig 
*it)
 {
        struct comedi_driver *driv;
-- 
1.8.1.4

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel

Reply via email to