mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stefan Richter <stefanr@s5r6.in-berlin.de>
To: Ben Collins <bcollins@ubuntu.com>
Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org
Subject: [PATCH 11/19] ieee1394: dv1394: sem2mutex conversion
Date: Mon, 3 Jul 2006 01:08:59 +0200 (CEST)	[thread overview]
Message-ID: <tkrat.6846050d082fee91@s5r6.in-berlin.de> (raw)
In-Reply-To: <tkrat.8d67352567e525c1@s5r6.in-berlin.de>

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de> (not runtime-tested)
---
 drivers/ieee1394/dv1394-private.h |    6 ++---
 drivers/ieee1394/dv1394.c         |   31 +++++++++++++++---------------
 2 files changed, 19 insertions(+), 18 deletions(-)

Index: linux/drivers/ieee1394/dv1394-private.h
===================================================================
--- linux.orig/drivers/ieee1394/dv1394-private.h	2006-07-01 09:16:48.000000000 +0200
+++ linux/drivers/ieee1394/dv1394-private.h	2006-07-01 20:50:48.000000000 +0200
@@ -460,7 +460,7 @@ struct video_card {
 	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
 	  open() is allowed, we still need to prevent multiple threads of execution
 	  from entering calls like read, write, ioctl, etc.
@@ -468,9 +468,9 @@ struct video_card {
 	  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 =).
 
-	  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... */
 	wait_queue_head_t waitq;
Index: linux/drivers/ieee1394/dv1394.c
===================================================================
--- linux.orig/drivers/ieee1394/dv1394.c	2006-07-01 17:42:38.000000000 +0200
+++ linux/drivers/ieee1394/dv1394.c	2006-07-01 20:50:48.000000000 +0200
@@ -95,6 +95,7 @@
 #include <linux/fs.h>
 #include <linux/poll.h>
 #include <linux/smp_lock.h>
+#include <linux/mutex.h>
 #include <linux/bitops.h>
 #include <asm/byteorder.h>
 #include <asm/atomic.h>
@@ -247,7 +248,7 @@ static void frame_delete(struct frame *f
 
    Frame_prepare() must be called OUTSIDE the video->spinlock.
    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)
@@ -1271,7 +1272,7 @@ static int dv1394_mmap(struct file *file
 	int retval = -EINVAL;
 
 	/* serialize mmap */
-	down(&video->sem);
+	mutex_lock(&video->mtx);
 
 	if ( ! video_card_initialized(video) ) {
 		retval = do_dv1394_init_default(video);
@@ -1281,7 +1282,7 @@ static int dv1394_mmap(struct file *file
 
 	retval = dma_region_mmap(&video->dv_buf, file, vma);
 out:
-	up(&video->sem);
+	mutex_unlock(&video->mtx);
 	return retval;
 }
 
@@ -1337,17 +1338,17 @@ static ssize_t dv1394_write(struct file 
 
 	/* serialize this to prevent multi-threaded mayhem */
 	if (file->f_flags & O_NONBLOCK) {
-		if (down_trylock(&video->sem))
+		if (!mutex_trylock(&video->mtx))
 			return -EAGAIN;
 	} else {
-		if (down_interruptible(&video->sem))
+		if (mutex_lock_interruptible(&video->mtx))
 			return -ERESTARTSYS;
 	}
 
 	if ( !video_card_initialized(video) ) {
 		ret = do_dv1394_init_default(video);
 		if (ret) {
-			up(&video->sem);
+			mutex_unlock(&video->mtx);
 			return ret;
 		}
 	}
@@ -1418,7 +1419,7 @@ static ssize_t dv1394_write(struct file 
 
 	remove_wait_queue(&video->waitq, &wait);
 	set_current_state(TASK_RUNNING);
-	up(&video->sem);
+	mutex_unlock(&video->mtx);
 	return ret;
 }
 
@@ -1434,17 +1435,17 @@ static ssize_t dv1394_read(struct file *
 
 	/* serialize this to prevent multi-threaded mayhem */
 	if (file->f_flags & O_NONBLOCK) {
-		if (down_trylock(&video->sem))
+		if (!mutex_trylock(&video->mtx))
 			return -EAGAIN;
 	} else {
-		if (down_interruptible(&video->sem))
+		if (mutex_lock_interruptible(&video->mtx))
 			return -ERESTARTSYS;
 	}
 
 	if ( !video_card_initialized(video) ) {
 		ret = do_dv1394_init_default(video);
 		if (ret) {
-			up(&video->sem);
+			mutex_unlock(&video->mtx);
 			return ret;
 		}
 		video->continuity_counter = -1;
@@ -1526,7 +1527,7 @@ static ssize_t dv1394_read(struct file *
 
 	remove_wait_queue(&video->waitq, &wait);
 	set_current_state(TASK_RUNNING);
-	up(&video->sem);
+	mutex_unlock(&video->mtx);
 	return ret;
 }
 
@@ -1547,12 +1548,12 @@ static long dv1394_ioctl(struct file *fi
 
 	/* serialize this to prevent multi-threaded mayhem */
 	if (file->f_flags & O_NONBLOCK) {
-		if (down_trylock(&video->sem)) {
+		if (!mutex_trylock(&video->mtx)) {
 			unlock_kernel();
 			return -EAGAIN;
 		}
 	} else {
-		if (down_interruptible(&video->sem)) {
+		if (mutex_lock_interruptible(&video->mtx)) {
 			unlock_kernel();
 			return -ERESTARTSYS;
 		}
@@ -1778,7 +1779,7 @@ static long dv1394_ioctl(struct file *fi
 	}
 
  out:
-	up(&video->sem);
+	mutex_unlock(&video->mtx);
 	unlock_kernel();
 	return ret;
 }
@@ -2253,7 +2254,7 @@ static int dv1394_init(struct ti_ohci *o
 	clear_bit(0, &video->open);
 	spin_lock_init(&video->spinlock);
 	video->dma_running = 0;
-	init_MUTEX(&video->sem);
+	mutex_init(&video->mtx);
 	init_waitqueue_head(&video->waitq);
 	video->fasync = NULL;
 



  parent reply	other threads:[~2006-07-02 23:09 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-02 22:53 [PATCH 00/19] ieee1394: misc updates Stefan Richter
2006-07-02 22:54 ` [PATCH 01/19] ieee1394: sbp2: enable auto spin-up for Maxtor disks Stefan Richter
2006-07-02 22:56 ` [PATCH 02/19] ieee1394: fix calculation of csr->expire Stefan Richter
2006-07-02 22:58 ` [PATCH 03/19] ieee1394: fix cosmetic problem in speed probe Stefan Richter
2006-07-02 22:59 ` [PATCH 04/19] ieee1394: skip dummy loop in build_speed_map Stefan Richter
2006-07-02 23:00 ` [PATCH 05/19] ieee1394: replace __inline__ by inline Stefan Richter
2006-07-02 23:02 ` [PATCH 06/19] ieee1394: coding style and comment fixes in midlayer header files Stefan Richter
2006-07-02 23:04 ` [PATCH 07/19] ieee1394: update #include directives " Stefan Richter
2006-07-02 23:05 ` [PATCH 08/19] ieee1394: remove redundant code from ieee1394_hotplug.h Stefan Richter
2006-07-02 23:06 ` [PATCH 09/19] ieee1394: remove unused macros HPSB_PANIC and HPSB_TRACE Stefan Richter
2006-07-02 23:07 ` [PATCH 10/19] ieee1394: clean up declarations of hpsb_*_config_rom Stefan Richter
2006-07-02 23:08 ` Stefan Richter [this message]
2006-07-02 23:20 ` [PATCH 12/19] ieee1394: raw1394: remove redundant counting semaphore Stefan Richter
2006-07-02 23:21 ` [PATCH 13/19] ieee1394: nodemgr: remove unnecessary includes Stefan Richter
2006-07-02 23:22 ` [PATCH 14/19] ieee1394: nodemgr: do not spawn kernel_thread for sysfs rescan Stefan Richter
2006-07-02 23:23 ` [PATCH 15/19] ieee1394: nodemgr: make module parameter ignore_drivers writable Stefan Richter
2006-07-02 23:25 ` [PATCH 16/19] ieee1394: nodemgr: switch to kthread api, replace reset semaphore Stefan Richter
2006-07-02 23:26 ` [PATCH 17/19] ieee1394: nodemgr: convert nodemgr_serialize semaphore to mutex Stefan Richter
2006-07-02 23:29 ` [PATCH 18/19] ieee1394: fix kerneldoc of hpsb_alloc_host Stefan Richter
2006-07-02 23:34   ` [PATCH 18a/19 2.6.17-mm5] " Stefan Richter
2006-07-02 23:31 ` [PATCH 19/19] ieee1394: shrink tlabel pools, remove tpool semaphores Stefan Richter
2006-07-03 16:05 ` [PATCH 00/19] ieee1394: misc updates Ben Collins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tkrat.6846050d082fee91@s5r6.in-berlin.de \
    --to=stefanr@s5r6.in-berlin.de \
    --cc=bcollins@ubuntu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux1394-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome