Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] ieee1394: dv1394: sem2mutex conversion

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de> (not runtime-tested)
Signed-off-by: Ben Collins <bcollins@ubuntu.com>

authored by

Stefan Richter and committed by
Ben Collins
438bd525 d8831d55

+19 -18
+3 -3
drivers/ieee1394/dv1394-private.h
··· 460 460 int dma_running; 461 461 462 462 /* 463 - 3) the sleeping semaphore 'sem' - this is used from process context only, 463 + 3) the sleeping mutex 'mtx' - this is used from process context only, 464 464 to serialize various operations on the video_card. Even though only one 465 465 open() is allowed, we still need to prevent multiple threads of execution 466 466 from entering calls like read, write, ioctl, etc. ··· 468 468 I honestly can't think of a good reason to use dv1394 from several threads 469 469 at once, but we need to serialize anyway to prevent oopses =). 470 470 471 - NOTE: if you need both spinlock and sem, take sem first to avoid deadlock! 471 + NOTE: if you need both spinlock and mtx, take mtx first to avoid deadlock! 472 472 */ 473 - struct semaphore sem; 473 + struct mutex mtx; 474 474 475 475 /* people waiting for buffer space, please form a line here... */ 476 476 wait_queue_head_t waitq;
+16 -15
drivers/ieee1394/dv1394.c
··· 95 95 #include <linux/fs.h> 96 96 #include <linux/poll.h> 97 97 #include <linux/smp_lock.h> 98 + #include <linux/mutex.h> 98 99 #include <linux/bitops.h> 99 100 #include <asm/byteorder.h> 100 101 #include <asm/atomic.h> ··· 248 247 249 248 Frame_prepare() must be called OUTSIDE the video->spinlock. 250 249 However, frame_prepare() must still be serialized, so 251 - it should be called WITH the video->sem taken. 250 + it should be called WITH the video->mtx taken. 252 251 */ 253 252 254 253 static void frame_prepare(struct video_card *video, unsigned int this_frame) ··· 1272 1271 int retval = -EINVAL; 1273 1272 1274 1273 /* serialize mmap */ 1275 - down(&video->sem); 1274 + mutex_lock(&video->mtx); 1276 1275 1277 1276 if ( ! video_card_initialized(video) ) { 1278 1277 retval = do_dv1394_init_default(video); ··· 1282 1281 1283 1282 retval = dma_region_mmap(&video->dv_buf, file, vma); 1284 1283 out: 1285 - up(&video->sem); 1284 + mutex_unlock(&video->mtx); 1286 1285 return retval; 1287 1286 } 1288 1287 ··· 1338 1337 1339 1338 /* serialize this to prevent multi-threaded mayhem */ 1340 1339 if (file->f_flags & O_NONBLOCK) { 1341 - if (down_trylock(&video->sem)) 1340 + if (!mutex_trylock(&video->mtx)) 1342 1341 return -EAGAIN; 1343 1342 } else { 1344 - if (down_interruptible(&video->sem)) 1343 + if (mutex_lock_interruptible(&video->mtx)) 1345 1344 return -ERESTARTSYS; 1346 1345 } 1347 1346 1348 1347 if ( !video_card_initialized(video) ) { 1349 1348 ret = do_dv1394_init_default(video); 1350 1349 if (ret) { 1351 - up(&video->sem); 1350 + mutex_unlock(&video->mtx); 1352 1351 return ret; 1353 1352 } 1354 1353 } ··· 1419 1418 1420 1419 remove_wait_queue(&video->waitq, &wait); 1421 1420 set_current_state(TASK_RUNNING); 1422 - up(&video->sem); 1421 + mutex_unlock(&video->mtx); 1423 1422 return ret; 1424 1423 } 1425 1424 ··· 1435 1434 1436 1435 /* serialize this to prevent multi-threaded mayhem */ 1437 1436 if (file->f_flags & O_NONBLOCK) { 1438 - if (down_trylock(&video->sem)) 1437 + if (!mutex_trylock(&video->mtx)) 1439 1438 return -EAGAIN; 1440 1439 } else { 1441 - if (down_interruptible(&video->sem)) 1440 + if (mutex_lock_interruptible(&video->mtx)) 1442 1441 return -ERESTARTSYS; 1443 1442 } 1444 1443 1445 1444 if ( !video_card_initialized(video) ) { 1446 1445 ret = do_dv1394_init_default(video); 1447 1446 if (ret) { 1448 - up(&video->sem); 1447 + mutex_unlock(&video->mtx); 1449 1448 return ret; 1450 1449 } 1451 1450 video->continuity_counter = -1; ··· 1527 1526 1528 1527 remove_wait_queue(&video->waitq, &wait); 1529 1528 set_current_state(TASK_RUNNING); 1530 - up(&video->sem); 1529 + mutex_unlock(&video->mtx); 1531 1530 return ret; 1532 1531 } 1533 1532 ··· 1548 1547 1549 1548 /* serialize this to prevent multi-threaded mayhem */ 1550 1549 if (file->f_flags & O_NONBLOCK) { 1551 - if (down_trylock(&video->sem)) { 1550 + if (!mutex_trylock(&video->mtx)) { 1552 1551 unlock_kernel(); 1553 1552 return -EAGAIN; 1554 1553 } 1555 1554 } else { 1556 - if (down_interruptible(&video->sem)) { 1555 + if (mutex_lock_interruptible(&video->mtx)) { 1557 1556 unlock_kernel(); 1558 1557 return -ERESTARTSYS; 1559 1558 } ··· 1779 1778 } 1780 1779 1781 1780 out: 1782 - up(&video->sem); 1781 + mutex_unlock(&video->mtx); 1783 1782 unlock_kernel(); 1784 1783 return ret; 1785 1784 } ··· 2254 2253 clear_bit(0, &video->open); 2255 2254 spin_lock_init(&video->spinlock); 2256 2255 video->dma_running = 0; 2257 - init_MUTEX(&video->sem); 2256 + mutex_init(&video->mtx); 2258 2257 init_waitqueue_head(&video->waitq); 2259 2258 video->fasync = NULL; 2260 2259