staging: comedi: mite: cleanup mite_unsetup()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Fri, 20 Jun 2014 18:10:35 +0000 (11:10 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 29 Jun 2014 21:17:59 +0000 (14:17 -0700)
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@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/mite.c
drivers/staging/comedi/drivers/mite.h
drivers/staging/comedi/drivers/ni_65xx.c
drivers/staging/comedi/drivers/ni_660x.c
drivers/staging/comedi/drivers/ni_670x.c
drivers/staging/comedi/drivers/ni_labpc_pci.c
drivers/staging/comedi/drivers/ni_pcidio.c
drivers/staging/comedi/drivers/ni_pcimio.c

index 19c029acbc99a51d94006af6fb69cd03a612abae..52d154886c4fdd3b59bd1c435d0eaa5d7b061cbb 100644 (file)
@@ -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)
 {
index 5137e18707fbd4304be78e722abb59cd12e786e8..a4852cbd5b312729775b63a7342452fc5b03844d 100644 (file)
@@ -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,
index 6e28603339b4fb309638d5aecce67d29f03f8dfb..59f592e0ca76ce29d59d07d116e43b6653602f41 100644 (file)
@@ -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);
 }
 
index 5f80bcabd40dc60b2ec3619e3a6c3ccf56c0d6cc..27d435f2565b6e0583c89c1a70f90ef7a9ee5074 100644 (file)
@@ -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);
 }
index 1002ceacfdcc9bc0db590b0156819be6ea06468d..b487f8d9eeed4c019a0d9b35b8eaa58be8da753b 100644 (file)
@@ -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);
 }
 
index 384c427092e4ea82be8e61152b8f130727c5f904..358c4af3e174e09e6921330111859e9f96b653fb 100644 (file)
@@ -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);
index b9de132350198114057c89847358b59f928326ac..4d6b2ed9ac7b9ce4207fa8ce682e2e0e712a8b3d 100644 (file)
@@ -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);
 }
index d72cc6f8aab2db5087a97800a2bebeb6c635988b..20c839b45752dbb1f8236503820e8b98503bd0cb 100644 (file)
@@ -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);
 }