From 514ff93208a16c74491470159848c7e0e1d97728 Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Thu, 19 Apr 2007 19:53:11 +0000 Subject: [PATCH] Added spinlock to mite_struct for mite_alloc_channel() and mite_free_channel(). --- comedi/drivers/mite.c | 20 +++++++++++++++----- comedi/drivers/mite.h | 1 + 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/comedi/drivers/mite.c b/comedi/drivers/mite.c index 81dd1449..076c8e57 100644 --- a/comedi/drivers/mite.c +++ b/comedi/drivers/mite.c @@ -83,7 +83,7 @@ void mite_init(void) return; } memset(mite,0,sizeof(*mite)); - + spin_lock_init(&mite->lock); mite->pcidev=pci_dev_get(pcidev); mite->next=mite_devices; @@ -224,24 +224,34 @@ void mite_list_devices(void) int mite_alloc_channel(struct mite_struct *mite) { - //FIXME spin lock so mite_free_channel can be called safely from interrupts int i; + unsigned long flags; + int retval = -1; + + // spin lock so mite_free_channel can be called safely from interrupts + comedi_spin_lock_irqsave(&mite->lock, flags); for(i = 0; i < mite->num_channels; ++i) { if(mite->channel_allocated[i] == 0) { mite->channel_allocated[i] = 1; - return i; + retval = i; + break; } } - return -1; + comedi_spin_unlock_irqrestore(&mite->lock, flags); + return retval; } void mite_free_channel(struct mite_struct *mite, unsigned channel) { - //FIXME spin lock to prevent races with mite_alloc_channel + unsigned long flags; + BUG_ON(channel >= mite->num_channels); + // spin lock to prevent races with mite_alloc_channel + comedi_spin_lock_irqsave(&mite->lock, flags); mite->channel_allocated[channel] = 0; + comedi_spin_unlock_irqrestore(&mite->lock, flags); } void mite_dma_arm( struct mite_struct *mite, unsigned int channel ) diff --git a/comedi/drivers/mite.h b/comedi/drivers/mite.h index 50dd58c4..387376b1 100644 --- a/comedi/drivers/mite.h +++ b/comedi/drivers/mite.h @@ -71,6 +71,7 @@ struct mite_struct{ struct mite_channel channels[MAX_MITE_DMA_CHANNELS]; short channel_allocated[MAX_MITE_DMA_CHANNELS]; int num_channels; + spinlock_t lock; }; extern struct mite_struct *mite_devices; -- 2.26.2