[PATCH 16/16] staging: comedi: mite: cleanup mite_unsetup()

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

 



This function is only called by comedi drivers during the (*detach) of the
driver. After it is called mite_free() is always called to kfree the allocated
mite_struct pointer.

Rename this function to mite_detach() and merge the kfree() from mite_free()
into it.

Remove the unnecessary clearing of the mite variables since the mite pointer
is going to be kfree()'d anyway.

The mite_detach() function checks if the pointer is valid so remove the
unnecessary checks in the callers.

The check can also be removed in ni_660x since the ni_660x_free_mite_rings()
function does not actually need the 'mite' pointer.

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregk@xxxxxxxxxxxxxxxxxxx>
---
 drivers/staging/comedi/drivers/mite.c         | 18 ++++++------------
 drivers/staging/comedi/drivers/mite.h         |  7 +------
 drivers/staging/comedi/drivers/ni_65xx.c      |  8 ++------
 drivers/staging/comedi/drivers/ni_660x.c      |  7 ++-----
 drivers/staging/comedi/drivers/ni_670x.c      |  6 ++----
 drivers/staging/comedi/drivers/ni_labpc_pci.c |  6 ++----
 drivers/staging/comedi/drivers/ni_pcidio.c    |  5 +----
 drivers/staging/comedi/drivers/ni_pcimio.c    |  5 +----
 8 files changed, 17 insertions(+), 45 deletions(-)

diff --git a/drivers/staging/comedi/drivers/mite.c b/drivers/staging/comedi/drivers/mite.c
index 19c029a..52d1548 100644
--- a/drivers/staging/comedi/drivers/mite.c
+++ b/drivers/staging/comedi/drivers/mite.c
@@ -173,25 +173,19 @@ int mite_setup(struct mite_struct *mite)
 }
 EXPORT_SYMBOL_GPL(mite_setup);
 
-void mite_unsetup(struct mite_struct *mite)
+void mite_detach(struct mite_struct *mite)
 {
-	/* unsigned long offset, start, length; */
-
 	if (!mite)
 		return;
 
-	if (mite->mite_io_addr) {
+	if (mite->mite_io_addr)
 		iounmap(mite->mite_io_addr);
-		mite->mite_io_addr = NULL;
-	}
-	if (mite->daq_io_addr) {
+	if (mite->daq_io_addr)
 		iounmap(mite->daq_io_addr);
-		mite->daq_io_addr = NULL;
-	}
-	if (mite->mite_phys_addr)
-		mite->mite_phys_addr = 0;
+
+	kfree(mite);
 }
-EXPORT_SYMBOL_GPL(mite_unsetup);
+EXPORT_SYMBOL_GPL(mite_detach);
 
 struct mite_dma_descriptor_ring *mite_alloc_ring(struct mite_struct *mite)
 {
diff --git a/drivers/staging/comedi/drivers/mite.h b/drivers/staging/comedi/drivers/mite.h
index 5137e18..a4852cb 100644
--- a/drivers/staging/comedi/drivers/mite.h
+++ b/drivers/staging/comedi/drivers/mite.h
@@ -65,14 +65,9 @@ struct mite_struct {
 
 struct mite_struct *mite_alloc(struct pci_dev *pcidev);
 
-static inline void mite_free(struct mite_struct *mite)
-{
-	kfree(mite);
-}
-
 int mite_setup(struct mite_struct *mite);
 int mite_setup2(struct mite_struct *mite, unsigned use_iodwbsr_1);
-void mite_unsetup(struct mite_struct *mite);
+void mite_detach(struct mite_struct *mite);
 struct mite_dma_descriptor_ring *mite_alloc_ring(struct mite_struct *mite);
 void mite_free_ring(struct mite_dma_descriptor_ring *ring);
 struct mite_channel *mite_request_channel_in_range(struct mite_struct *mite,
diff --git a/drivers/staging/comedi/drivers/ni_65xx.c b/drivers/staging/comedi/drivers/ni_65xx.c
index 6e28603..59f592e 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -716,12 +716,8 @@ static void ni_65xx_detach(struct comedi_device *dev)
 	}
 	if (dev->irq)
 		free_irq(dev->irq, dev);
-	if (devpriv) {
-		if (devpriv->mite) {
-			mite_unsetup(devpriv->mite);
-			mite_free(devpriv->mite);
-		}
-	}
+	if (devpriv)
+		mite_detach(devpriv->mite);
 	comedi_pci_disable(dev);
 }
 
diff --git a/drivers/staging/comedi/drivers/ni_660x.c b/drivers/staging/comedi/drivers/ni_660x.c
index 5f80bca..27d435f 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -1195,11 +1195,8 @@ static void ni_660x_detach(struct comedi_device *dev)
 	if (devpriv) {
 		if (devpriv->counter_dev)
 			ni_gpct_device_destroy(devpriv->counter_dev);
-		if (devpriv->mite) {
-			ni_660x_free_mite_rings(dev);
-			mite_unsetup(devpriv->mite);
-			mite_free(devpriv->mite);
-		}
+		ni_660x_free_mite_rings(dev);
+		mite_detach(devpriv->mite);
 	}
 	comedi_pci_disable(dev);
 }
diff --git a/drivers/staging/comedi/drivers/ni_670x.c b/drivers/staging/comedi/drivers/ni_670x.c
index 1002cea..b487f8d 100644
--- a/drivers/staging/comedi/drivers/ni_670x.c
+++ b/drivers/staging/comedi/drivers/ni_670x.c
@@ -259,10 +259,8 @@ static void ni_670x_detach(struct comedi_device *dev)
 		if (s)
 			kfree(s->range_table_list);
 	}
-	if (devpriv && devpriv->mite) {
-		mite_unsetup(devpriv->mite);
-		mite_free(devpriv->mite);
-	}
+	if (devpriv)
+		mite_detach(devpriv->mite);
 	comedi_pci_disable(dev);
 }
 
diff --git a/drivers/staging/comedi/drivers/ni_labpc_pci.c b/drivers/staging/comedi/drivers/ni_labpc_pci.c
index 384c427..358c4af 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_pci.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_pci.c
@@ -91,10 +91,8 @@ static void labpc_pci_detach(struct comedi_device *dev)
 {
 	struct labpc_private *devpriv = dev->private;
 
-	if (devpriv && devpriv->mite) {
-		mite_unsetup(devpriv->mite);
-		mite_free(devpriv->mite);
-	}
+	if (devpriv)
+		mite_detach(devpriv->mite);
 	if (dev->irq)
 		free_irq(dev->irq, dev);
 	comedi_pci_disable(dev);
diff --git a/drivers/staging/comedi/drivers/ni_pcidio.c b/drivers/staging/comedi/drivers/ni_pcidio.c
index b9de132..4d6b2ed 100644
--- a/drivers/staging/comedi/drivers/ni_pcidio.c
+++ b/drivers/staging/comedi/drivers/ni_pcidio.c
@@ -1046,10 +1046,7 @@ static void nidio_detach(struct comedi_device *dev)
 			mite_free_ring(devpriv->di_mite_ring);
 			devpriv->di_mite_ring = NULL;
 		}
-		if (devpriv->mite) {
-			mite_unsetup(devpriv->mite);
-			mite_free(devpriv->mite);
-		}
+		mite_detach(devpriv->mite);
 	}
 	comedi_pci_disable(dev);
 }
diff --git a/drivers/staging/comedi/drivers/ni_pcimio.c b/drivers/staging/comedi/drivers/ni_pcimio.c
index d72cc6f..20c839b 100644
--- a/drivers/staging/comedi/drivers/ni_pcimio.c
+++ b/drivers/staging/comedi/drivers/ni_pcimio.c
@@ -1189,10 +1189,7 @@ static void pcimio_detach(struct comedi_device *dev)
 		mite_free_ring(devpriv->cdo_mite_ring);
 		mite_free_ring(devpriv->gpct_mite_ring[0]);
 		mite_free_ring(devpriv->gpct_mite_ring[1]);
-		if (devpriv->mite) {
-			mite_unsetup(devpriv->mite);
-			mite_free(devpriv->mite);
-		}
+		mite_detach(devpriv->mite);
 	}
 	comedi_pci_disable(dev);
 }
-- 
1.9.3

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-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