Re: [PATCH 01/12] staging: comedi: drivers: introduce comedi_legacy_detach()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2013-04-17 19:16, H Hartley Sweeten wrote:
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 first
struct resource returned by request_region() in the comedi_device.

The comedi_legacy_detach() function will then automatically release the
region during the detach of the driver.

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
  drivers/staging/comedi/comedidev.h |  2 ++
  drivers/staging/comedi/drivers.c   | 29 ++++++++++++++++++++++++++++-
  2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h
index ce509d0..48dfe16 100644
--- a/drivers/staging/comedi/comedidev.h
+++ b/drivers/staging/comedi/comedidev.h
@@ -215,6 +215,7 @@ struct comedi_device {
  	struct comedi_subdevice *subdevices;

  	/* dumb */
+	struct resource *res;
  	unsigned long iobase;
  	unsigned int irq;

@@ -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..cb5f0d5 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -121,6 +121,7 @@ static void cleanup_device(struct comedi_device *dev)
  	dev->driver = NULL;
  	dev->board_name = NULL;
  	dev->board_ptr = NULL;
+	dev->res = NULL;
  	dev->iobase = 0;
  	dev->ioenabled = false;
  	dev->irq = 0;
@@ -358,6 +359,8 @@ static void comedi_report_boards(struct comedi_driver *driv)
  int __comedi_request_region(struct comedi_device *dev,
  			    unsigned long start, unsigned long len)
  {
+	struct resource *res;
+
  	if (!start) {
  		dev_warn(dev->class_dev,
  			 "%s: a I/O base address must be specified\n",
@@ -365,12 +368,23 @@ int __comedi_request_region(struct comedi_device *dev,
  		return -EINVAL;
  	}

-	if (!request_region(start, len, dev->board_name)) {
+	res = request_region(start, len, dev->board_name);
+	if (!res) {
  		dev_warn(dev->class_dev, "%s: I/O port conflict (%#lx,%lu)\n",
  			 dev->board_name, start, len);
  		return -EIO;
  	}

+	/*
+	 * Save the resource of the first region requested by a driver.
+	 * comedi_legacy_detach() will automatically release that region.
+	 *
+	 * If a driver request additional regions, it must release those
+	 * regions during the (*detach).
+	 */
+	if (!dev->res)
+		dev->res = res;
+
  	return 0;
  }
  EXPORT_SYMBOL_GPL(__comedi_request_region);
@@ -394,6 +408,19 @@ int comedi_request_region(struct comedi_device *dev,
  }
  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->res) {
+		release_region(dev->res->start, resource_size(dev->res));
+		dev->res = NULL;
+	}
+}
+EXPORT_SYMBOL_GPL(comedi_legacy_detach);
+
  int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it)
  {
  	struct comedi_driver *driv;


An alternative implementation would be to leave __comedi_request_region() alone, but change comedi_request_region() to record the length in a new member dev->iolen at the same time that it records the start address in dev->iobase. Then your comedi_legacy_detach() could do something like:

	if (dev->iolen) {
		release_region(dev->iobase, dev->iolen);
		dev->iolen = 0;
	}

I think it seems slightly simpler and shouldn't affect your other patches. Any thoughts?

--
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti@xxxxxxxxx>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-
_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux