staging: comedi: mite: add mite_alloc() and mite_free()
authorIan Abbott <abbotti@mev.co.uk>
Fri, 14 Sep 2012 16:34:25 +0000 (17:34 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 17 Sep 2012 12:09:08 +0000 (05:09 -0700)
Add `mite_alloc()` to allow drivers to allocate and initialize a `struct
mite_struct` dynamically and export it.  Add `mite_free()`, which is
currently just an inline wrapper for `kfree()`.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/mite.c
drivers/staging/comedi/drivers/mite.h

index b63f86ce9c1f2c505e35a3b3576b5c2b2743a5e5..7355455f0abe18cb819d7bf155860c7560ff9b64 100644 (file)
@@ -66,6 +66,25 @@ EXPORT_SYMBOL(mite_devices);
 
 #define TOP_OF_PAGE(x) ((x)|(~(PAGE_MASK)))
 
+struct mite_struct *mite_alloc(struct pci_dev *pcidev)
+{
+       struct mite_struct *mite;
+       unsigned int i;
+
+       mite = kzalloc(sizeof(*mite), GFP_KERNEL);
+       if (mite) {
+               spin_lock_init(&mite->lock);
+               mite->pcidev = pcidev;
+               for (i = 0; i < MAX_MITE_DMA_CHANNELS; ++i) {
+                       mite->channels[i].mite = mite;
+                       mite->channels[i].channel = i;
+                       mite->channels[i].done = 1;
+               }
+       }
+       return mite;
+}
+EXPORT_SYMBOL(mite_alloc);
+
 static void mite_init(void)
 {
        struct pci_dev *pcidev = NULL;
@@ -73,21 +92,13 @@ static void mite_init(void)
 
        for_each_pci_dev(pcidev) {
                if (pcidev->vendor == PCI_VENDOR_ID_NI) {
-                       unsigned i;
-
-                       mite = kzalloc(sizeof(*mite), GFP_KERNEL);
+                       mite = mite_alloc(pcidev);
                        if (!mite) {
                                pr_err("allocation failed\n");
                                pci_dev_put(pcidev);
                                return;
                        }
-                       spin_lock_init(&mite->lock);
-                       mite->pcidev = pci_dev_get(pcidev);
-                       for (i = 0; i < MAX_MITE_DMA_CHANNELS; ++i) {
-                               mite->channels[i].mite = mite;
-                               mite->channels[i].channel = i;
-                               mite->channels[i].done = 1;
-                       }
+                       pci_dev_get(pcidev);
                        mite->next = mite_devices;
                        mite_devices = mite;
                }
@@ -213,7 +224,7 @@ static void mite_cleanup(void)
        for (mite = mite_devices; mite; mite = next) {
                pci_dev_put(mite->pcidev);
                next = mite->next;
-               kfree(mite);
+               mite_free(mite);
        }
 }
 
index c5157c37ef125410aff3398a6a20e9403d0c915e..912bae171c92274e45c7abb3252c77632e2aeb7d 100644 (file)
@@ -80,6 +80,13 @@ struct mite_struct {
 
 extern struct mite_struct *mite_devices;
 
+struct mite_struct *mite_alloc(struct pci_dev *pcidev);
+
+static inline void mite_free(struct mite_struct *mite)
+{
+       kfree(mite);
+}
+
 static inline unsigned int mite_irq(struct mite_struct *mite)
 {
        return mite->pcidev->irq;