All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil@xs4all.nl>
To: linux-media@vger.kernel.org
Cc: Arnd Bergmann <arnd@arndb.de>
Subject: [RFC PATCH 1/8] v4l2-dev: use mutex_lock_interruptible instead of plain mutex_lock
Date: Sun, 14 Nov 2010 14:22:13 +0100	[thread overview]
Message-ID: <a1d7a499591515e1746a02af64dfff5a95089a46.1289740431.git.hverkuil@xs4all.nl> (raw)
In-Reply-To: <cover.1289740431.git.hverkuil@xs4all.nl>

Where reasonable use mutex_lock_interruptible instead of mutex_lock.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
---
 drivers/media/video/v4l2-dev.c |   44 +++++++++++++++++++++++++++++----------
 1 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
index 0ca7978..8eb0756 100644
--- a/drivers/media/video/v4l2-dev.c
+++ b/drivers/media/video/v4l2-dev.c
@@ -191,8 +191,12 @@ static ssize_t v4l2_read(struct file *filp, char __user *buf,
 
 	if (!vdev->fops->read)
 		return -EINVAL;
-	if (vdev->lock)
-		mutex_lock(vdev->lock);
+	if (vdev->lock) {
+		int res = mutex_lock_interruptible(vdev->lock);
+
+		if (res)
+			return res;
+	}
 	if (video_is_registered(vdev))
 		ret = vdev->fops->read(filp, buf, sz, off);
 	if (vdev->lock)
@@ -208,8 +212,12 @@ static ssize_t v4l2_write(struct file *filp, const char __user *buf,
 
 	if (!vdev->fops->write)
 		return -EINVAL;
-	if (vdev->lock)
-		mutex_lock(vdev->lock);
+	if (vdev->lock) {
+		int res = mutex_lock_interruptible(vdev->lock);
+
+		if (res)
+			return res;
+	}
 	if (video_is_registered(vdev))
 		ret = vdev->fops->write(filp, buf, sz, off);
 	if (vdev->lock)
@@ -224,8 +232,8 @@ static unsigned int v4l2_poll(struct file *filp, struct poll_table_struct *poll)
 
 	if (!vdev->fops->poll)
 		return ret;
-	if (vdev->lock)
-		mutex_lock(vdev->lock);
+	if (vdev->lock && mutex_lock_interruptible(vdev->lock))
+		return ret;
 	if (video_is_registered(vdev))
 		ret = vdev->fops->poll(filp, poll);
 	if (vdev->lock)
@@ -239,8 +247,12 @@ static long v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 	int ret = -ENODEV;
 
 	if (vdev->fops->unlocked_ioctl) {
-		if (vdev->lock)
-			mutex_lock(vdev->lock);
+		if (vdev->lock) {
+			int res = mutex_lock_interruptible(vdev->lock);
+
+			if (res)
+				return res;
+		}
 		if (video_is_registered(vdev))
 			ret = vdev->fops->unlocked_ioctl(filp, cmd, arg);
 		if (vdev->lock)
@@ -264,8 +276,12 @@ static int v4l2_mmap(struct file *filp, struct vm_area_struct *vm)
 
 	if (!vdev->fops->mmap)
 		return ret;
-	if (vdev->lock)
-		mutex_lock(vdev->lock);
+	if (vdev->lock) {
+		int res = mutex_lock_interruptible(vdev->lock);
+
+		if (res)
+			return res;
+	}
 	if (video_is_registered(vdev))
 		ret = vdev->fops->mmap(filp, vm);
 	if (vdev->lock)
@@ -291,8 +307,11 @@ static int v4l2_open(struct inode *inode, struct file *filp)
 	video_get(vdev);
 	mutex_unlock(&videodev_lock);
 	if (vdev->fops->open) {
-		if (vdev->lock)
-			mutex_lock(vdev->lock);
+		if (vdev->lock) {
+			ret = mutex_lock_interruptible(vdev->lock);
+			if (ret)
+				goto err;
+		}
 		if (video_is_registered(vdev))
 			ret = vdev->fops->open(filp);
 		else
@@ -301,6 +320,7 @@ static int v4l2_open(struct inode *inode, struct file *filp)
 			mutex_unlock(vdev->lock);
 	}
 
+err:
 	/* decrease the refcount in case of an error */
 	if (ret)
 		video_put(vdev);
-- 
1.7.0.4


  reply	other threads:[~2010-11-14 13:22 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-14 13:21 [RFC PATCH 0/8] V4L BKL removal: first round Hans Verkuil
2010-11-14 13:22 ` Hans Verkuil [this message]
2010-11-14 13:22 ` [RFC PATCH 2/8] BKL: trivial BKL removal from V4L2 radio drivers Hans Verkuil
2010-11-14 13:22 ` [RFC PATCH 3/8] cadet: use unlocked_ioctl Hans Verkuil
2010-11-14 13:22 ` [RFC PATCH 4/8] tea5764: convert to unlocked_ioctl Hans Verkuil
2010-11-14 13:22 ` [RFC PATCH 5/8] si4713: " Hans Verkuil
2010-11-14 13:22 ` [RFC PATCH 6/8] typhoon: " Hans Verkuil
2010-11-14 13:23 ` [RFC PATCH 7/8] dsbr100: " Hans Verkuil
2010-11-14 13:23 ` [RFC PATCH 8/8] BKL: trivial ioctl -> unlocked_ioctl video driver conversions Hans Verkuil
2010-11-14 21:53 ` [RFC PATCH 0/8] V4L BKL removal: first round Arnd Bergmann
2010-11-14 22:48   ` Hans Verkuil
2010-11-15  9:17     ` Arnd Bergmann
2010-11-15  9:49       ` Hans Verkuil
2010-11-16 12:19         ` Mauro Carvalho Chehab
2010-11-16 12:35           ` Hans Verkuil
2010-11-16 13:06             ` Mauro Carvalho Chehab
2010-11-16 13:20               ` Hans Verkuil
2010-11-16 14:22                 ` Arnd Bergmann
2010-11-16 14:50                   ` Hans Verkuil
2010-11-16 15:13                     ` Arnd Bergmann
2010-11-16 15:27                       ` Hans Verkuil
2010-11-16 15:30                         ` Hans Verkuil
2010-11-16 16:01                           ` Arnd Bergmann
2010-11-16 16:32                             ` Mauro Carvalho Chehab
2010-11-16 16:49                             ` Hans Verkuil
2010-11-16 18:38                               ` Hans Verkuil
2010-11-16 19:23                                 ` Arnd Bergmann
2010-11-16 19:59                                 ` Andy Walls
2010-11-16 20:29                                   ` Hans Verkuil
2010-11-16 21:10                                     ` Hans Verkuil
2010-11-16 21:32                                       ` David Ellingsworth
2010-11-16 21:42                                         ` Hans Verkuil
2010-11-17 15:36                                           ` David Ellingsworth

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=a1d7a499591515e1746a02af64dfff5a95089a46.1289740431.git.hverkuil@xs4all.nl \
    --to=hverkuil@xs4all.nl \
    --cc=arnd@arndb.de \
    --cc=linux-media@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.