···460460 int dma_running;461461462462 /*463463- 3) the sleeping semaphore 'sem' - this is used from process context only,463463+ 3) the sleeping mutex 'mtx' - this is used from process context only,464464 to serialize various operations on the video_card. Even though only one465465 open() is allowed, we still need to prevent multiple threads of execution466466 from entering calls like read, write, ioctl, etc.···468468 I honestly can't think of a good reason to use dv1394 from several threads469469 at once, but we need to serialize anyway to prevent oopses =).470470471471- NOTE: if you need both spinlock and sem, take sem first to avoid deadlock!471471+ NOTE: if you need both spinlock and mtx, take mtx first to avoid deadlock!472472 */473473- struct semaphore sem;473473+ struct mutex mtx;474474475475 /* people waiting for buffer space, please form a line here... */476476 wait_queue_head_t waitq;
+16-15
drivers/ieee1394/dv1394.c
···9595#include <linux/fs.h>9696#include <linux/poll.h>9797#include <linux/smp_lock.h>9898+#include <linux/mutex.h>9899#include <linux/bitops.h>99100#include <asm/byteorder.h>100101#include <asm/atomic.h>···248247249248 Frame_prepare() must be called OUTSIDE the video->spinlock.250249 However, frame_prepare() must still be serialized, so251251- it should be called WITH the video->sem taken.250250+ it should be called WITH the video->mtx taken.252251 */253252254253static void frame_prepare(struct video_card *video, unsigned int this_frame)···12721271 int retval = -EINVAL;1273127212741273 /* serialize mmap */12751275- down(&video->sem);12741274+ mutex_lock(&video->mtx);1276127512771276 if ( ! video_card_initialized(video) ) {12781277 retval = do_dv1394_init_default(video);···1282128112831282 retval = dma_region_mmap(&video->dv_buf, file, vma);12841283out:12851285- up(&video->sem);12841284+ mutex_unlock(&video->mtx);12861285 return retval;12871286}12881287···1338133713391338 /* serialize this to prevent multi-threaded mayhem */13401339 if (file->f_flags & O_NONBLOCK) {13411341- if (down_trylock(&video->sem))13401340+ if (!mutex_trylock(&video->mtx))13421341 return -EAGAIN;13431342 } else {13441344- if (down_interruptible(&video->sem))13431343+ if (mutex_lock_interruptible(&video->mtx))13451344 return -ERESTARTSYS;13461345 }1347134613481347 if ( !video_card_initialized(video) ) {13491348 ret = do_dv1394_init_default(video);13501349 if (ret) {13511351- up(&video->sem);13501350+ mutex_unlock(&video->mtx);13521351 return ret;13531352 }13541353 }···1419141814201419 remove_wait_queue(&video->waitq, &wait);14211420 set_current_state(TASK_RUNNING);14221422- up(&video->sem);14211421+ mutex_unlock(&video->mtx);14231422 return ret;14241423}14251424···1435143414361435 /* serialize this to prevent multi-threaded mayhem */14371436 if (file->f_flags & O_NONBLOCK) {14381438- if (down_trylock(&video->sem))14371437+ if (!mutex_trylock(&video->mtx))14391438 return -EAGAIN;14401439 } else {14411441- if (down_interruptible(&video->sem))14401440+ if (mutex_lock_interruptible(&video->mtx))14421441 return -ERESTARTSYS;14431442 }1444144314451444 if ( !video_card_initialized(video) ) {14461445 ret = do_dv1394_init_default(video);14471446 if (ret) {14481448- up(&video->sem);14471447+ mutex_unlock(&video->mtx);14491448 return ret;14501449 }14511450 video->continuity_counter = -1;···1527152615281527 remove_wait_queue(&video->waitq, &wait);15291528 set_current_state(TASK_RUNNING);15301530- up(&video->sem);15291529+ mutex_unlock(&video->mtx);15311530 return ret;15321531}15331532···1548154715491548 /* serialize this to prevent multi-threaded mayhem */15501549 if (file->f_flags & O_NONBLOCK) {15511551- if (down_trylock(&video->sem)) {15501550+ if (!mutex_trylock(&video->mtx)) {15521551 unlock_kernel();15531552 return -EAGAIN;15541553 }15551554 } else {15561556- if (down_interruptible(&video->sem)) {15551555+ if (mutex_lock_interruptible(&video->mtx)) {15571556 unlock_kernel();15581557 return -ERESTARTSYS;15591558 }···17791778 }1780177917811780 out:17821782- up(&video->sem);17811781+ mutex_unlock(&video->mtx);17831782 unlock_kernel();17841783 return ret;17851784}···22542253 clear_bit(0, &video->open);22552254 spin_lock_init(&video->spinlock);22562255 video->dma_running = 0;22572257- init_MUTEX(&video->sem);22562256+ mutex_init(&video->mtx);22582257 init_waitqueue_head(&video->waitq);22592258 video->fasync = NULL;22602259