Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/parisc-2.6
[pandora-kernel.git] / drivers / media / video / v4l2-dev.c
index 6b1ef85..6dc7196 100644 (file)
@@ -143,6 +143,7 @@ static inline void video_put(struct video_device *vdev)
 static void v4l2_device_release(struct device *cd)
 {
        struct video_device *vdev = to_video_device(cd);
+       struct v4l2_device *v4l2_dev = vdev->v4l2_dev;
 
        mutex_lock(&videodev_lock);
        if (video_device[vdev->minor] != vdev) {
@@ -169,6 +170,10 @@ static void v4l2_device_release(struct device *cd)
        /* Release video_device and perform other
           cleanups as needed. */
        vdev->release(vdev);
+
+       /* Decrease v4l2_device refcount */
+       if (v4l2_dev)
+               v4l2_device_put(v4l2_dev);
 }
 
 static struct class video_class = {
@@ -384,7 +389,8 @@ static int v4l2_open(struct inode *inode, struct file *filp)
        video_get(vdev);
        mutex_unlock(&videodev_lock);
 #if defined(CONFIG_MEDIA_CONTROLLER)
-       if (vdev->v4l2_dev && vdev->v4l2_dev->mdev) {
+       if (vdev->v4l2_dev && vdev->v4l2_dev->mdev &&
+           vdev->vfl_type != VFL_TYPE_SUBDEV) {
                entity = media_entity_get(&vdev->entity);
                if (!entity) {
                        ret = -EBUSY;
@@ -410,7 +416,8 @@ err:
        /* decrease the refcount in case of an error */
        if (ret) {
 #if defined(CONFIG_MEDIA_CONTROLLER)
-               if (vdev->v4l2_dev && vdev->v4l2_dev->mdev)
+               if (vdev->v4l2_dev && vdev->v4l2_dev->mdev &&
+                   vdev->vfl_type != VFL_TYPE_SUBDEV)
                        media_entity_put(entity);
 #endif
                video_put(vdev);
@@ -432,7 +439,8 @@ static int v4l2_release(struct inode *inode, struct file *filp)
                        mutex_unlock(vdev->lock);
        }
 #if defined(CONFIG_MEDIA_CONTROLLER)
-       if (vdev->v4l2_dev && vdev->v4l2_dev->mdev)
+       if (vdev->v4l2_dev && vdev->v4l2_dev->mdev &&
+           vdev->vfl_type != VFL_TYPE_SUBDEV)
                media_entity_put(&vdev->entity);
 #endif
        /* decrease the refcount unconditionally since the release()
@@ -573,11 +581,9 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
                        vdev->parent = vdev->v4l2_dev->dev;
                if (vdev->ctrl_handler == NULL)
                        vdev->ctrl_handler = vdev->v4l2_dev->ctrl_handler;
-               /* If the prio state pointer is NULL, and if the driver doesn't
-                  handle priorities itself, then use the v4l2_device prio
-                  state. */
-               if (vdev->prio == NULL && vdev->ioctl_ops &&
-                               vdev->ioctl_ops->vidioc_s_priority == NULL)
+               /* If the prio state pointer is NULL, then use the v4l2_device
+                  prio state. */
+               if (vdev->prio == NULL)
                        vdev->prio = &vdev->v4l2_dev->prio;
        }
 
@@ -676,9 +682,15 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
        if (nr != -1 && nr != vdev->num && warn_if_nr_in_use)
                printk(KERN_WARNING "%s: requested %s%d, got %s\n", __func__,
                        name_base, nr, video_device_node_name(vdev));
+
+       /* Increase v4l2_device refcount */
+       if (vdev->v4l2_dev)
+               v4l2_device_get(vdev->v4l2_dev);
+
 #if defined(CONFIG_MEDIA_CONTROLLER)
        /* Part 5: Register the entity. */
-       if (vdev->v4l2_dev && vdev->v4l2_dev->mdev) {
+       if (vdev->v4l2_dev && vdev->v4l2_dev->mdev &&
+           vdev->vfl_type != VFL_TYPE_SUBDEV) {
                vdev->entity.type = MEDIA_ENT_T_DEVNODE_V4L;
                vdev->entity.name = vdev->name;
                vdev->entity.v4l.major = VIDEO_MAJOR;
@@ -725,7 +737,8 @@ void video_unregister_device(struct video_device *vdev)
                return;
 
 #if defined(CONFIG_MEDIA_CONTROLLER)
-       if (vdev->v4l2_dev && vdev->v4l2_dev->mdev)
+       if (vdev->v4l2_dev && vdev->v4l2_dev->mdev &&
+           vdev->vfl_type != VFL_TYPE_SUBDEV)
                media_device_unregister_entity(&vdev->entity);
 #endif