summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorIan Abbott2014-10-29 18:35:12 +0100
committerGreg Kroah-Hartman2014-10-30 21:29:31 +0100
commit0a43f75ef57fcf20b9637fa49889e6721ceb5ea7 (patch)
treed88b8a8677bb521ae77ce04bc93d794c0c33aa96 /drivers
parentstaging: comedi: das16: deschedule timer routine on detach (diff)
downloadkernel-qcow2-linux-0a43f75ef57fcf20b9637fa49889e6721ceb5ea7.tar.gz
kernel-qcow2-linux-0a43f75ef57fcf20b9637fa49889e6721ceb5ea7.tar.xz
kernel-qcow2-linux-0a43f75ef57fcf20b9637fa49889e6721ceb5ea7.zip
staging: comedi: das16: use spin-lock when setting timer
"das16" sets a timer running in `das16_cmd_exec()` and sets `devpriv->timer_running` to indicate that it is running. The timer expiration routine `das16_timer_interrupt()` checks `devpriv->timer_running` to check whether it needs to reschedule the timer, but this is not synchronized with `das16_cmd_exec()`. Since `das16_cancel()` acquires the `dev->spinlock` spin-lock when clearing `devpriv->timer_running` and removing the timer from the queue, use the same spin-lock in `das16_cmd_exec()` and `das16_timer_interrupt()` around the setting and checking of `devpriv->timer_running`. Since `das16_interrupt()` (called from `das16_timer_interrupt()`) checks whether DMA is enabled in the device while holding `dev->spinlock`, and DMA is enabled by `das16_cmd_exec()` around the time it schedules the timer, enable the DMA in the device while holding the spin-lock. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/staging/comedi/drivers/das16.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/drivers/staging/comedi/drivers/das16.c b/drivers/staging/comedi/drivers/das16.c
index 4556af109eae..8e512b241653 100644
--- a/drivers/staging/comedi/drivers/das16.c
+++ b/drivers/staging/comedi/drivers/das16.c
@@ -595,11 +595,14 @@ static void das16_timer_interrupt(unsigned long arg)
{
struct comedi_device *dev = (struct comedi_device *)arg;
struct das16_private_struct *devpriv = dev->private;
+ unsigned long flags;
das16_interrupt(dev);
+ spin_lock_irqsave(&dev->spinlock, flags);
if (devpriv->timer_running)
mod_timer(&devpriv->timer, jiffies + timer_period());
+ spin_unlock_irqrestore(&dev->spinlock, flags);
}
static int das16_ai_check_chanlist(struct comedi_device *dev,
@@ -816,7 +819,8 @@ static int das16_cmd_exec(struct comedi_device *dev, struct comedi_subdevice *s)
enable_dma(devpriv->dma_chan);
release_dma_lock(flags);
- /* set up interrupt */
+ /* set up timer */
+ spin_lock_irqsave(&dev->spinlock, flags);
devpriv->timer_running = 1;
devpriv->timer.expires = jiffies + timer_period();
add_timer(&devpriv->timer);
@@ -825,6 +829,7 @@ static int das16_cmd_exec(struct comedi_device *dev, struct comedi_subdevice *s)
if (devpriv->can_burst)
outb(0, dev->iobase + DAS1600_CONV_REG);
+ spin_unlock_irqrestore(&dev->spinlock, flags);
return 0;
}