Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1383734

[PATCH] media: fix media_open() to not release lock too soon

From Shuah Khan <shuahkh@osg.samsung.com>
Newsgroups linux.kernel
Subject [PATCH] media: fix media_open() to not release lock too soon
Date 2016-04-20 22:50 +0200
Message-ID <rq7eq-5Ab-11@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


media_open() releases media_devnode_lock before open is complete. Hold
the lock to call mdev->fops->open and release at the end.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 drivers/media/media-devnode.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/media/media-devnode.c b/drivers/media/media-devnode.c
index 29409f4..0934789 100644
--- a/drivers/media/media-devnode.c
+++ b/drivers/media/media-devnode.c
@@ -155,7 +155,7 @@ static long media_compat_ioctl(struct file *filp, unsigned int cmd,
 static int media_open(struct inode *inode, struct file *filp)
 {
 	struct media_devnode *mdev;
-	int ret;
+	int ret = 0;
 
 	/* Check if the media device is available. This needs to be done with
 	 * the media_devnode_lock held to prevent an open/unregister race:
@@ -173,7 +173,6 @@ static int media_open(struct inode *inode, struct file *filp)
 	}
 	/* and increase the device refcount */
 	get_device(&mdev->dev);
-	mutex_unlock(&media_devnode_lock);
 
 	filp->private_data = mdev;
 
@@ -182,11 +181,12 @@ static int media_open(struct inode *inode, struct file *filp)
 		if (ret) {
 			put_device(&mdev->dev);
 			filp->private_data = NULL;
-			return ret;
+			goto done;
 		}
 	}
-
-	return 0;
+done:
+	mutex_unlock(&media_devnode_lock);
+	return ret;
 }
 
 /* Override for the release function */
-- 
2.5.0

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] media: fix media_open() to not release lock too soon Shuah Khan <shuahkh@osg.samsung.com> - 2016-04-20 22:50 +0200
  Re: [PATCH] media: fix media_open() to not release lock too soon Mauro Carvalho Chehab <mchehab@osg.samsung.com> - 2016-04-22 15:40 +0200

csiph-web