Skip to content

Commit

Permalink
staging: comedi: mite: add mite_alloc() and mite_free()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Ian Abbott authored and Greg Kroah-Hartman committed Sep 17, 2012
1 parent d799773 commit ca8eb8d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
33 changes: 22 additions & 11 deletions drivers/staging/comedi/drivers/mite.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,39 @@ 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;
struct mite_struct *mite;

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;
}
Expand Down Expand Up @@ -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);
}
}

Expand Down
7 changes: 7 additions & 0 deletions drivers/staging/comedi/drivers/mite.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ca8eb8d

Please sign in to comment.