diff options
author | Ian Abbott <abbotti@mev.co.uk> | 2012-09-14 17:34:25 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-09-17 05:09:08 -0700 |
commit | ca8eb8d5c8aa1a0828d381b213b14e13961f5297 (patch) | |
tree | c0a1a4a3c6aa716565bd562900cdc60ac7679cf5 /drivers | |
parent | d799773f6837b44f4dca8d298c2be4d524d3331e (diff) | |
download | linux-3.10-ca8eb8d5c8aa1a0828d381b213b14e13961f5297.tar.gz linux-3.10-ca8eb8d5c8aa1a0828d381b213b14e13961f5297.tar.bz2 linux-3.10-ca8eb8d5c8aa1a0828d381b213b14e13961f5297.zip |
staging: comedi: mite: add mite_alloc() and mite_free()
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>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/staging/comedi/drivers/mite.c | 33 | ||||
-rw-r--r-- | drivers/staging/comedi/drivers/mite.h | 7 |
2 files changed, 29 insertions, 11 deletions
diff --git a/drivers/staging/comedi/drivers/mite.c b/drivers/staging/comedi/drivers/mite.c index b63f86ce9c1..7355455f0ab 100644 --- a/drivers/staging/comedi/drivers/mite.c +++ b/drivers/staging/comedi/drivers/mite.c @@ -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); } } diff --git a/drivers/staging/comedi/drivers/mite.h b/drivers/staging/comedi/drivers/mite.h index c5157c37ef1..912bae171c9 100644 --- a/drivers/staging/comedi/drivers/mite.h +++ b/drivers/staging/comedi/drivers/mite.h @@ -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; |