The video device depends on the existence of its media device --- if there
is one. Acquire a reference to it.

Signed-off-by: Sakari Ailus <[email protected]>
---
 drivers/media/v4l2-core/v4l2-dev.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/v4l2-dev.c 
b/drivers/media/v4l2-core/v4l2-dev.c
index 70b559d..80cc675 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -171,6 +171,7 @@ static void v4l2_device_release(struct device *cd)
 {
        struct video_device *vdev = to_video_device(cd);
        struct v4l2_device *v4l2_dev = vdev->v4l2_dev;
+       struct media_device *mdev = v4l2_dev->mdev;
 
        mutex_lock(&videodev_lock);
        if (WARN_ON(video_device[vdev->minor] != vdev)) {
@@ -194,7 +195,7 @@ static void v4l2_device_release(struct device *cd)
        mutex_unlock(&videodev_lock);
 
 #if defined(CONFIG_MEDIA_CONTROLLER)
-       if (v4l2_dev->mdev) {
+       if (mdev) {
                /* Remove interfaces and interface links */
                media_devnode_remove(vdev->intf_devnode);
                if (vdev->entity.function != MEDIA_ENT_F_UNKNOWN)
@@ -220,6 +221,11 @@ static void v4l2_device_release(struct device *cd)
        /* Decrease v4l2_device refcount */
        if (v4l2_dev)
                v4l2_device_put(v4l2_dev);
+
+#if defined(CONFIG_MEDIA_CONTROLLER)
+       if (mdev)
+               media_device_put(mdev);
+#endif
 }
 
 static struct class video_class = {
@@ -808,6 +814,7 @@ static int video_register_media_controller(struct 
video_device *vdev, int type)
 
        /* FIXME: how to create the other interface links? */
 
+       media_device_get(vdev->v4l2_dev->mdev);
 #endif
        return 0;
 }
-- 
2.1.4

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

Reply via email to