From: Hans Verkuil <hans.verk...@cisco.com>

In order to efficiently handle V4L2_REQ_CMD_QUEUE we need to know which
video_device structs are registered for the given v4l2_device struct.

So create a list of vdevs in v4l2_device and add/remove each video_device
there as it is registered/unregistered.

Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/v4l2-core/v4l2-dev.c    | 8 ++++++++
 drivers/media/v4l2-core/v4l2-device.c | 1 +
 include/media/v4l2-dev.h              | 3 +++
 include/media/v4l2-device.h           | 2 ++
 4 files changed, 14 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-dev.c 
b/drivers/media/v4l2-core/v4l2-dev.c
index ff206f1..a11e35d 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -768,6 +768,8 @@ int __video_register_device(struct video_device *vdev, int 
type, int nr,
        if (WARN_ON(!vdev->v4l2_dev))
                return -EINVAL;
 
+       INIT_LIST_HEAD(&vdev->list);
+
        /* v4l2_fh support */
        spin_lock_init(&vdev->fh_lock);
        INIT_LIST_HEAD(&vdev->fh_list);
@@ -927,6 +929,9 @@ int __video_register_device(struct video_device *vdev, int 
type, int nr,
 #endif
        /* Part 6: Activate this minor. The char device can now be used. */
        set_bit(V4L2_FL_REGISTERED, &vdev->flags);
+       spin_lock(&vdev->v4l2_dev->lock);
+       list_add_tail(&vdev->list, &vdev->v4l2_dev->vdevs);
+       spin_unlock(&vdev->v4l2_dev->lock);
 
        return 0;
 
@@ -962,6 +967,9 @@ void video_unregister_device(struct video_device *vdev)
         */
        clear_bit(V4L2_FL_REGISTERED, &vdev->flags);
        mutex_unlock(&videodev_lock);
+       spin_lock(&vdev->v4l2_dev->lock);
+       list_del(&vdev->list);
+       spin_unlock(&vdev->v4l2_dev->lock);
        device_unregister(&vdev->dev);
 }
 EXPORT_SYMBOL(video_unregister_device);
diff --git a/drivers/media/v4l2-core/v4l2-device.c 
b/drivers/media/v4l2-core/v4l2-device.c
index 5b0a30b..cdb2d72 100644
--- a/drivers/media/v4l2-core/v4l2-device.c
+++ b/drivers/media/v4l2-core/v4l2-device.c
@@ -36,6 +36,7 @@ int v4l2_device_register(struct device *dev, struct 
v4l2_device *v4l2_dev)
                return -EINVAL;
 
        INIT_LIST_HEAD(&v4l2_dev->subdevs);
+       INIT_LIST_HEAD(&v4l2_dev->vdevs);
        spin_lock_init(&v4l2_dev->lock);
        v4l2_prio_init(&v4l2_dev->prio);
        kref_init(&v4l2_dev->ref);
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index acbcd2f..a5a3401 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -84,6 +84,9 @@ struct v4l2_file_operations {
 
 struct video_device
 {
+       /* links into v4l2_device vdevs list */
+       struct list_head list;
+
 #if defined(CONFIG_MEDIA_CONTROLLER)
        struct media_entity entity;
 #endif
diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
index 603e7f3..6484e54 100644
--- a/include/media/v4l2-device.h
+++ b/include/media/v4l2-device.h
@@ -46,6 +46,8 @@ struct v4l2_device {
 #endif
        /* used to keep track of the registered subdevs */
        struct list_head subdevs;
+       /* used to keep track of the registered video_devices */
+       struct list_head vdevs;
        /* lock this struct; can be used by the driver as well if this
           struct is embedded into a larger struct. */
        spinlock_t lock;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to