Commit 438bd525 authored by Stefan Richter's avatar Stefan Richter Committed by Ben Collins

[PATCH] ieee1394: dv1394: sem2mutex conversion

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de> (not runtime-tested)
Signed-off-by: default avatarBen Collins <bcollins@ubuntu.com>
parent d8831d55
...@@ -460,7 +460,7 @@ struct video_card { ...@@ -460,7 +460,7 @@ struct video_card {
int dma_running; int dma_running;
/* /*
3) the sleeping semaphore 'sem' - this is used from process context only, 3) the sleeping mutex 'mtx' - this is used from process context only,
to serialize various operations on the video_card. Even though only one to serialize various operations on the video_card. Even though only one
open() is allowed, we still need to prevent multiple threads of execution open() is allowed, we still need to prevent multiple threads of execution
from entering calls like read, write, ioctl, etc. from entering calls like read, write, ioctl, etc.
...@@ -468,9 +468,9 @@ struct video_card { ...@@ -468,9 +468,9 @@ struct video_card {
I honestly can't think of a good reason to use dv1394 from several threads I honestly can't think of a good reason to use dv1394 from several threads
at once, but we need to serialize anyway to prevent oopses =). at once, but we need to serialize anyway to prevent oopses =).
NOTE: if you need both spinlock and sem, take sem first to avoid deadlock! NOTE: if you need both spinlock and mtx, take mtx first to avoid deadlock!
*/ */
struct semaphore sem; struct mutex mtx;
/* people waiting for buffer space, please form a line here... */ /* people waiting for buffer space, please form a line here... */
wait_queue_head_t waitq; wait_queue_head_t waitq;
......
...@@ -95,6 +95,7 @@ ...@@ -95,6 +95,7 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/poll.h> #include <linux/poll.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/mutex.h>
#include <linux/bitops.h> #include <linux/bitops.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>
#include <asm/atomic.h> #include <asm/atomic.h>
...@@ -247,7 +248,7 @@ static void frame_delete(struct frame *f) ...@@ -247,7 +248,7 @@ static void frame_delete(struct frame *f)
Frame_prepare() must be called OUTSIDE the video->spinlock. Frame_prepare() must be called OUTSIDE the video->spinlock.
However, frame_prepare() must still be serialized, so However, frame_prepare() must still be serialized, so
it should be called WITH the video->sem taken. it should be called WITH the video->mtx taken.
*/ */
static void frame_prepare(struct video_card *video, unsigned int this_frame) static void frame_prepare(struct video_card *video, unsigned int this_frame)
...@@ -1271,7 +1272,7 @@ static int dv1394_mmap(struct file *file, struct vm_area_struct *vma) ...@@ -1271,7 +1272,7 @@ static int dv1394_mmap(struct file *file, struct vm_area_struct *vma)
int retval = -EINVAL; int retval = -EINVAL;
/* serialize mmap */ /* serialize mmap */
down(&video->sem); mutex_lock(&video->mtx);
if ( ! video_card_initialized(video) ) { if ( ! video_card_initialized(video) ) {
retval = do_dv1394_init_default(video); retval = do_dv1394_init_default(video);
...@@ -1281,7 +1282,7 @@ static int dv1394_mmap(struct file *file, struct vm_area_struct *vma) ...@@ -1281,7 +1282,7 @@ static int dv1394_mmap(struct file *file, struct vm_area_struct *vma)
retval = dma_region_mmap(&video->dv_buf, file, vma); retval = dma_region_mmap(&video->dv_buf, file, vma);
out: out:
up(&video->sem); mutex_unlock(&video->mtx);
return retval; return retval;
} }
...@@ -1337,17 +1338,17 @@ static ssize_t dv1394_write(struct file *file, const char __user *buffer, size_t ...@@ -1337,17 +1338,17 @@ static ssize_t dv1394_write(struct file *file, const char __user *buffer, size_t
/* serialize this to prevent multi-threaded mayhem */ /* serialize this to prevent multi-threaded mayhem */
if (file->f_flags & O_NONBLOCK) { if (file->f_flags & O_NONBLOCK) {
if (down_trylock(&video->sem)) if (!mutex_trylock(&video->mtx))
return -EAGAIN; return -EAGAIN;
} else { } else {
if (down_interruptible(&video->sem)) if (mutex_lock_interruptible(&video->mtx))
return -ERESTARTSYS; return -ERESTARTSYS;
} }
if ( !video_card_initialized(video) ) { if ( !video_card_initialized(video) ) {
ret = do_dv1394_init_default(video); ret = do_dv1394_init_default(video);
if (ret) { if (ret) {
up(&video->sem); mutex_unlock(&video->mtx);
return ret; return ret;
} }
} }
...@@ -1418,7 +1419,7 @@ static ssize_t dv1394_write(struct file *file, const char __user *buffer, size_t ...@@ -1418,7 +1419,7 @@ static ssize_t dv1394_write(struct file *file, const char __user *buffer, size_t
remove_wait_queue(&video->waitq, &wait); remove_wait_queue(&video->waitq, &wait);
set_current_state(TASK_RUNNING); set_current_state(TASK_RUNNING);
up(&video->sem); mutex_unlock(&video->mtx);
return ret; return ret;
} }
...@@ -1434,17 +1435,17 @@ static ssize_t dv1394_read(struct file *file, char __user *buffer, size_t count ...@@ -1434,17 +1435,17 @@ static ssize_t dv1394_read(struct file *file, char __user *buffer, size_t count
/* serialize this to prevent multi-threaded mayhem */ /* serialize this to prevent multi-threaded mayhem */
if (file->f_flags & O_NONBLOCK) { if (file->f_flags & O_NONBLOCK) {
if (down_trylock(&video->sem)) if (!mutex_trylock(&video->mtx))
return -EAGAIN; return -EAGAIN;
} else { } else {
if (down_interruptible(&video->sem)) if (mutex_lock_interruptible(&video->mtx))
return -ERESTARTSYS; return -ERESTARTSYS;
} }
if ( !video_card_initialized(video) ) { if ( !video_card_initialized(video) ) {
ret = do_dv1394_init_default(video); ret = do_dv1394_init_default(video);
if (ret) { if (ret) {
up(&video->sem); mutex_unlock(&video->mtx);
return ret; return ret;
} }
video->continuity_counter = -1; video->continuity_counter = -1;
...@@ -1526,7 +1527,7 @@ static ssize_t dv1394_read(struct file *file, char __user *buffer, size_t count ...@@ -1526,7 +1527,7 @@ static ssize_t dv1394_read(struct file *file, char __user *buffer, size_t count
remove_wait_queue(&video->waitq, &wait); remove_wait_queue(&video->waitq, &wait);
set_current_state(TASK_RUNNING); set_current_state(TASK_RUNNING);
up(&video->sem); mutex_unlock(&video->mtx);
return ret; return ret;
} }
...@@ -1547,12 +1548,12 @@ static long dv1394_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -1547,12 +1548,12 @@ static long dv1394_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
/* serialize this to prevent multi-threaded mayhem */ /* serialize this to prevent multi-threaded mayhem */
if (file->f_flags & O_NONBLOCK) { if (file->f_flags & O_NONBLOCK) {
if (down_trylock(&video->sem)) { if (!mutex_trylock(&video->mtx)) {
unlock_kernel(); unlock_kernel();
return -EAGAIN; return -EAGAIN;
} }
} else { } else {
if (down_interruptible(&video->sem)) { if (mutex_lock_interruptible(&video->mtx)) {
unlock_kernel(); unlock_kernel();
return -ERESTARTSYS; return -ERESTARTSYS;
} }
...@@ -1778,7 +1779,7 @@ static long dv1394_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -1778,7 +1779,7 @@ static long dv1394_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
} }
out: out:
up(&video->sem); mutex_unlock(&video->mtx);
unlock_kernel(); unlock_kernel();
return ret; return ret;
} }
...@@ -2253,7 +2254,7 @@ static int dv1394_init(struct ti_ohci *ohci, enum pal_or_ntsc format, enum modes ...@@ -2253,7 +2254,7 @@ static int dv1394_init(struct ti_ohci *ohci, enum pal_or_ntsc format, enum modes
clear_bit(0, &video->open); clear_bit(0, &video->open);
spin_lock_init(&video->spinlock); spin_lock_init(&video->spinlock);
video->dma_running = 0; video->dma_running = 0;
init_MUTEX(&video->sem); mutex_init(&video->mtx);
init_waitqueue_head(&video->waitq); init_waitqueue_head(&video->waitq);
video->fasync = NULL; video->fasync = NULL;
......
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