diff options
author | Stefan Richter <stefanr@s5r6.in-berlin.de> | 2006-07-03 12:02:32 -0400 |
---|---|---|
committer | Ben Collins <bcollins@ubuntu.com> | 2006-07-03 12:02:32 -0400 |
commit | 438bd525e5240a48233cd3290f7fe66ff0167e20 (patch) | |
tree | 5559a543c9ff18290b29fded7e20522308fea5dc /drivers/ieee1394 | |
parent | d8831d5554c2f295a6746e9d3b4cbd8bb13a540f (diff) |
[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>
Diffstat (limited to 'drivers/ieee1394')
-rw-r--r-- | drivers/ieee1394/dv1394-private.h | 6 | ||||
-rw-r--r-- | drivers/ieee1394/dv1394.c | 31 |
2 files changed, 19 insertions, 18 deletions
diff --git a/drivers/ieee1394/dv1394-private.h b/drivers/ieee1394/dv1394-private.h index 80b5ac7fe383..7d1d2845b420 100644 --- a/drivers/ieee1394/dv1394-private.h +++ b/drivers/ieee1394/dv1394-private.h | |||
@@ -460,7 +460,7 @@ struct video_card { | |||
460 | int dma_running; | 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 | to serialize various operations on the video_card. Even though only one | 464 | to serialize various operations on the video_card. Even though only one |
465 | open() is allowed, we still need to prevent multiple threads of execution | 465 | open() is allowed, we still need to prevent multiple threads of execution |
466 | from entering calls like read, write, ioctl, etc. | 466 | from entering calls like read, write, ioctl, etc. |
@@ -468,9 +468,9 @@ struct video_card { | |||
468 | I honestly can't think of a good reason to use dv1394 from several threads | 468 | I honestly can't think of a good reason to use dv1394 from several threads |
469 | at once, but we need to serialize anyway to prevent oopses =). | 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 | /* people waiting for buffer space, please form a line here... */ | 475 | /* people waiting for buffer space, please form a line here... */ |
476 | wait_queue_head_t waitq; | 476 | wait_queue_head_t waitq; |
diff --git a/drivers/ieee1394/dv1394.c b/drivers/ieee1394/dv1394.c index bdc50f25fb42..6e71d68b1099 100644 --- a/drivers/ieee1394/dv1394.c +++ b/drivers/ieee1394/dv1394.c | |||
@@ -95,6 +95,7 @@ | |||
95 | #include <linux/fs.h> | 95 | #include <linux/fs.h> |
96 | #include <linux/poll.h> | 96 | #include <linux/poll.h> |
97 | #include <linux/smp_lock.h> | 97 | #include <linux/smp_lock.h> |
98 | #include <linux/mutex.h> | ||
98 | #include <linux/bitops.h> | 99 | #include <linux/bitops.h> |
99 | #include <asm/byteorder.h> | 100 | #include <asm/byteorder.h> |
100 | #include <asm/atomic.h> | 101 | #include <asm/atomic.h> |
@@ -247,7 +248,7 @@ static void frame_delete(struct frame *f) | |||
247 | 248 | ||
248 | Frame_prepare() must be called OUTSIDE the video->spinlock. | 249 | Frame_prepare() must be called OUTSIDE the video->spinlock. |
249 | However, frame_prepare() must still be serialized, so | 250 | However, frame_prepare() must still be serialized, so |
250 | it should be called WITH the video->sem taken. | 251 | it should be called WITH the video->mtx taken. |
251 | */ | 252 | */ |
252 | 253 | ||
253 | static void frame_prepare(struct video_card *video, unsigned int this_frame) | 254 | 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 | int retval = -EINVAL; | 1272 | int retval = -EINVAL; |
1272 | 1273 | ||
1273 | /* serialize mmap */ | 1274 | /* serialize mmap */ |
1274 | down(&video->sem); | 1275 | mutex_lock(&video->mtx); |
1275 | 1276 | ||
1276 | if ( ! video_card_initialized(video) ) { | 1277 | if ( ! video_card_initialized(video) ) { |
1277 | retval = do_dv1394_init_default(video); | 1278 | retval = do_dv1394_init_default(video); |
@@ -1281,7 +1282,7 @@ static int dv1394_mmap(struct file *file, struct vm_area_struct *vma) | |||
1281 | 1282 | ||
1282 | retval = dma_region_mmap(&video->dv_buf, file, vma); | 1283 | retval = dma_region_mmap(&video->dv_buf, file, vma); |
1283 | out: | 1284 | out: |
1284 | up(&video->sem); | 1285 | mutex_unlock(&video->mtx); |
1285 | return retval; | 1286 | return retval; |
1286 | } | 1287 | } |
1287 | 1288 | ||
@@ -1337,17 +1338,17 @@ static ssize_t dv1394_write(struct file *file, const char __user *buffer, size_t | |||
1337 | 1338 | ||
1338 | /* serialize this to prevent multi-threaded mayhem */ | 1339 | /* serialize this to prevent multi-threaded mayhem */ |
1339 | if (file->f_flags & O_NONBLOCK) { | 1340 | if (file->f_flags & O_NONBLOCK) { |
1340 | if (down_trylock(&video->sem)) | 1341 | if (!mutex_trylock(&video->mtx)) |
1341 | return -EAGAIN; | 1342 | return -EAGAIN; |
1342 | } else { | 1343 | } else { |
1343 | if (down_interruptible(&video->sem)) | 1344 | if (mutex_lock_interruptible(&video->mtx)) |
1344 | return -ERESTARTSYS; | 1345 | return -ERESTARTSYS; |
1345 | } | 1346 | } |
1346 | 1347 | ||
1347 | if ( !video_card_initialized(video) ) { | 1348 | if ( !video_card_initialized(video) ) { |
1348 | ret = do_dv1394_init_default(video); | 1349 | ret = do_dv1394_init_default(video); |
1349 | if (ret) { | 1350 | if (ret) { |
1350 | up(&video->sem); | 1351 | mutex_unlock(&video->mtx); |
1351 | return ret; | 1352 | return ret; |
1352 | } | 1353 | } |
1353 | } | 1354 | } |
@@ -1418,7 +1419,7 @@ static ssize_t dv1394_write(struct file *file, const char __user *buffer, size_t | |||
1418 | 1419 | ||
1419 | remove_wait_queue(&video->waitq, &wait); | 1420 | remove_wait_queue(&video->waitq, &wait); |
1420 | set_current_state(TASK_RUNNING); | 1421 | set_current_state(TASK_RUNNING); |
1421 | up(&video->sem); | 1422 | mutex_unlock(&video->mtx); |
1422 | return ret; | 1423 | return ret; |
1423 | } | 1424 | } |
1424 | 1425 | ||
@@ -1434,17 +1435,17 @@ static ssize_t dv1394_read(struct file *file, char __user *buffer, size_t count | |||
1434 | 1435 | ||
1435 | /* serialize this to prevent multi-threaded mayhem */ | 1436 | /* serialize this to prevent multi-threaded mayhem */ |
1436 | if (file->f_flags & O_NONBLOCK) { | 1437 | if (file->f_flags & O_NONBLOCK) { |
1437 | if (down_trylock(&video->sem)) | 1438 | if (!mutex_trylock(&video->mtx)) |
1438 | return -EAGAIN; | 1439 | return -EAGAIN; |
1439 | } else { | 1440 | } else { |
1440 | if (down_interruptible(&video->sem)) | 1441 | if (mutex_lock_interruptible(&video->mtx)) |
1441 | return -ERESTARTSYS; | 1442 | return -ERESTARTSYS; |
1442 | } | 1443 | } |
1443 | 1444 | ||
1444 | if ( !video_card_initialized(video) ) { | 1445 | if ( !video_card_initialized(video) ) { |
1445 | ret = do_dv1394_init_default(video); | 1446 | ret = do_dv1394_init_default(video); |
1446 | if (ret) { | 1447 | if (ret) { |
1447 | up(&video->sem); | 1448 | mutex_unlock(&video->mtx); |
1448 | return ret; | 1449 | return ret; |
1449 | } | 1450 | } |
1450 | video->continuity_counter = -1; | 1451 | video->continuity_counter = -1; |
@@ -1526,7 +1527,7 @@ static ssize_t dv1394_read(struct file *file, char __user *buffer, size_t count | |||
1526 | 1527 | ||
1527 | remove_wait_queue(&video->waitq, &wait); | 1528 | remove_wait_queue(&video->waitq, &wait); |
1528 | set_current_state(TASK_RUNNING); | 1529 | set_current_state(TASK_RUNNING); |
1529 | up(&video->sem); | 1530 | mutex_unlock(&video->mtx); |
1530 | return ret; | 1531 | return ret; |
1531 | } | 1532 | } |
1532 | 1533 | ||
@@ -1547,12 +1548,12 @@ static long dv1394_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
1547 | 1548 | ||
1548 | /* serialize this to prevent multi-threaded mayhem */ | 1549 | /* serialize this to prevent multi-threaded mayhem */ |
1549 | if (file->f_flags & O_NONBLOCK) { | 1550 | if (file->f_flags & O_NONBLOCK) { |
1550 | if (down_trylock(&video->sem)) { | 1551 | if (!mutex_trylock(&video->mtx)) { |
1551 | unlock_kernel(); | 1552 | unlock_kernel(); |
1552 | return -EAGAIN; | 1553 | return -EAGAIN; |
1553 | } | 1554 | } |
1554 | } else { | 1555 | } else { |
1555 | if (down_interruptible(&video->sem)) { | 1556 | if (mutex_lock_interruptible(&video->mtx)) { |
1556 | unlock_kernel(); | 1557 | unlock_kernel(); |
1557 | return -ERESTARTSYS; | 1558 | return -ERESTARTSYS; |
1558 | } | 1559 | } |
@@ -1778,7 +1779,7 @@ static long dv1394_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
1778 | } | 1779 | } |
1779 | 1780 | ||
1780 | out: | 1781 | out: |
1781 | up(&video->sem); | 1782 | mutex_unlock(&video->mtx); |
1782 | unlock_kernel(); | 1783 | unlock_kernel(); |
1783 | return ret; | 1784 | return ret; |
1784 | } | 1785 | } |
@@ -2253,7 +2254,7 @@ static int dv1394_init(struct ti_ohci *ohci, enum pal_or_ntsc format, enum modes | |||
2253 | clear_bit(0, &video->open); | 2254 | clear_bit(0, &video->open); |
2254 | spin_lock_init(&video->spinlock); | 2255 | spin_lock_init(&video->spinlock); |
2255 | video->dma_running = 0; | 2256 | video->dma_running = 0; |
2256 | init_MUTEX(&video->sem); | 2257 | mutex_init(&video->mtx); |
2257 | init_waitqueue_head(&video->waitq); | 2258 | init_waitqueue_head(&video->waitq); |
2258 | video->fasync = NULL; | 2259 | video->fasync = NULL; |
2259 | 2260 | ||