diff mbox

[4/7,RFC] v4l2-dev: add and support flag V4L2_FH_USE_PRIO.

Message ID 32667ffc68c4ff35e1a5693f79ca429c427cc4f0.1273432986.git.hverkuil@xs4all.nl (mailing list archive)
State RFC
Headers show

Commit Message

Hans Verkuil May 9, 2010, 7:29 p.m. UTC
None
diff mbox

Patch

diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
index 0ca7ec9..fd536ff 100644
--- a/drivers/media/video/v4l2-dev.c
+++ b/drivers/media/video/v4l2-dev.c
@@ -283,6 +283,15 @@  static int v4l2_open(struct inode *inode, struct file *filp)
 	/* and increase the device refcount */
 	video_get(vdev);
 	mutex_unlock(&videodev_lock);
+
+	if (test_bit(V4L2_FL_USES_V4L2_PRIO, &vdev->flags)) {
+		enum v4l2_priority prio =
+			(enum v4l2_priority)filp->private_data;
+
+		v4l2_prio_open(&vdev->v4l2_dev->prio, &prio);
+		filp->private_data = (void *)prio;
+	}
+
 	if (vdev->fops->open)
 		ret = vdev->fops->open(filp);
 
@@ -296,15 +305,20 @@  static int v4l2_open(struct inode *inode, struct file *filp)
 static int v4l2_release(struct inode *inode, struct file *filp)
 {
 	struct video_device *vdev = video_devdata(filp);
-	int ret = 0;
 
+	if (test_bit(V4L2_FL_USES_V4L2_PRIO, &vdev->flags)) {
+		enum v4l2_priority prio =
+			(enum v4l2_priority)filp->private_data;
+
+		v4l2_prio_close(&vdev->v4l2_dev->prio, prio);
+	}
 	if (vdev->fops->release)
 		vdev->fops->release(filp);
 
 	/* decrease the refcount unconditionally since the release()
 	   return value is ignored. */
 	video_put(vdev);
-	return ret;
+	return 0;
 }
 
 static const struct file_operations v4l2_unlocked_fops = {
@@ -515,6 +529,11 @@  static int __video_register_device(struct video_device *vdev, int type, int nr,
 	vdev->index = get_index(vdev);
 	mutex_unlock(&videodev_lock);
 
+	/* Determine if we can store v4l2_priority in file->private_data */
+	if (vdev->fops->open == NULL && vdev->fops->release == NULL &&
+	    vdev->v4l2_dev != NULL)
+		set_bit(V4L2_FL_USES_V4L2_PRIO, &vdev->flags);
+
 	/* Part 3: Initialize the character device */
 	vdev->cdev = cdev_alloc();
 	if (vdev->cdev == NULL) {
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index bebe44b..a116bc5 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -32,7 +32,13 @@  struct v4l2_device;
    Drivers can clear this flag if they want to block all future
    device access. It is cleared by video_unregister_device. */
 #define V4L2_FL_REGISTERED	(0)
+/* Flag to mark that the driver stores a pointer to struct v4l2_fh in
+   file->private_data. Is automatically detected. */
 #define V4L2_FL_USES_V4L2_FH	(1)
+/* Flag to mark that the driver stores the local v4l2_priority in
+   file->private_data. Will be used if open and release are both NULL.
+   Drivers can also set it manually. */
+#define V4L2_FL_USES_V4L2_PRIO	(2)
 
 struct v4l2_file_operations {
 	struct module *owner;