Commit ca8eb8d5 authored by Ian Abbott's avatar Ian Abbott Committed by Greg Kroah-Hartman

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: default avatarIan Abbott <abbotti@mev.co.uk>
Reviewed-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent d799773f
...@@ -66,6 +66,25 @@ EXPORT_SYMBOL(mite_devices); ...@@ -66,6 +66,25 @@ EXPORT_SYMBOL(mite_devices);
#define TOP_OF_PAGE(x) ((x)|(~(PAGE_MASK))) #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) static void mite_init(void)
{ {
struct pci_dev *pcidev = NULL; struct pci_dev *pcidev = NULL;
...@@ -73,21 +92,13 @@ static void mite_init(void) ...@@ -73,21 +92,13 @@ static void mite_init(void)
for_each_pci_dev(pcidev) { for_each_pci_dev(pcidev) {
if (pcidev->vendor == PCI_VENDOR_ID_NI) { if (pcidev->vendor == PCI_VENDOR_ID_NI) {
unsigned i; mite = mite_alloc(pcidev);
mite = kzalloc(sizeof(*mite), GFP_KERNEL);
if (!mite) { if (!mite) {
pr_err("allocation failed\n"); pr_err("allocation failed\n");
pci_dev_put(pcidev); pci_dev_put(pcidev);
return; return;
} }
spin_lock_init(&mite->lock); pci_dev_get(pcidev);
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;
}
mite->next = mite_devices; mite->next = mite_devices;
mite_devices = mite; mite_devices = mite;
} }
...@@ -213,7 +224,7 @@ static void mite_cleanup(void) ...@@ -213,7 +224,7 @@ static void mite_cleanup(void)
for (mite = mite_devices; mite; mite = next) { for (mite = mite_devices; mite; mite = next) {
pci_dev_put(mite->pcidev); pci_dev_put(mite->pcidev);
next = mite->next; next = mite->next;
kfree(mite); mite_free(mite);
} }
} }
......
...@@ -80,6 +80,13 @@ struct mite_struct { ...@@ -80,6 +80,13 @@ struct mite_struct {
extern struct mite_struct *mite_devices; 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) static inline unsigned int mite_irq(struct mite_struct *mite)
{ {
return mite->pcidev->irq; return mite->pcidev->irq;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment