]> Pileus Git - ~andy/linux/commitdiff
[media] v4l2: always require v4l2_dev, rename parent to dev_parent
authorHans Verkuil <hans.verkuil@cisco.com>
Wed, 12 Jun 2013 14:15:12 +0000 (11:15 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Fri, 21 Jun 2013 14:07:12 +0000 (11:07 -0300)
The last set of drivers still using the parent field of video_device instead
of the v4l2_dev field have been converted, so v4l2_dev is now always set.
A proper pointer to v4l2_dev is necessary these days otherwise the advanced
debugging ioctls will not work when addressing sub-devices. It also ensures
that the core can always go from a video_device struct to the top-level
v4l2_device struct.
There is still one single use case for the parent pointer: if there are
multiple busses, each being the parent of one or more video nodes, and if
they all share the same v4l2_device struct. In that case one still needs a
parent pointer since the v4l2_device struct can only refer to a single
parent device. The cx88 driver is one such case. Unfortunately, the cx88
failed to set the parent pointer since 3.6. The next patch will correct this.
In order to support this use-case the parent pointer is only renamed to
dev_parent, not removed altogether. It has been renamed to ensure that the
compiler will catch any (possibly out-of-tree) drivers that were missed during
the conversion.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Sakari Ailus <sakari.ailus@iki.fi>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/v4l2-core/v4l2-dev.c
drivers/media/v4l2-core/v4l2-ioctl.c
include/media/v4l2-dev.h

index 0c061e16502e79082735315dd0285e7af094ba64..c8859d6ff6ad14e4aaf0ba6192ffe9613edcea8b 100644 (file)
@@ -495,8 +495,8 @@ static const struct file_operations v4l2_fops = {
 };
 
 /**
- * get_index - assign stream index number based on parent device
- * @vdev: video_device to assign index number to, vdev->parent should be assigned
+ * get_index - assign stream index number based on v4l2_dev
+ * @vdev: video_device to assign index number to, vdev->v4l2_dev should be assigned
  *
  * Note that when this is called the new device has not yet been registered
  * in the video_device array, but it was able to obtain a minor number.
@@ -514,15 +514,11 @@ static int get_index(struct video_device *vdev)
        static DECLARE_BITMAP(used, VIDEO_NUM_DEVICES);
        int i;
 
-       /* Some drivers do not set the parent. In that case always return 0. */
-       if (vdev->parent == NULL)
-               return 0;
-
        bitmap_zero(used, VIDEO_NUM_DEVICES);
 
        for (i = 0; i < VIDEO_NUM_DEVICES; i++) {
                if (video_device[i] != NULL &&
-                   video_device[i]->parent == vdev->parent) {
+                   video_device[i]->v4l2_dev == vdev->v4l2_dev) {
                        set_bit(video_device[i]->index, used);
                }
        }
@@ -775,6 +771,9 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
        /* the release callback MUST be present */
        if (WARN_ON(!vdev->release))
                return -EINVAL;
+       /* the v4l2_dev pointer MUST be present */
+       if (WARN_ON(!vdev->v4l2_dev))
+               return -EINVAL;
 
        /* v4l2_fh support */
        spin_lock_init(&vdev->fh_lock);
@@ -802,16 +801,14 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
 
        vdev->vfl_type = type;
        vdev->cdev = NULL;
-       if (vdev->v4l2_dev) {
-               if (vdev->v4l2_dev->dev)
-                       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, then use the v4l2_device
-                  prio state. */
-               if (vdev->prio == NULL)
-                       vdev->prio = &vdev->v4l2_dev->prio;
-       }
+       if (vdev->dev_parent == NULL)
+               vdev->dev_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, then use the v4l2_device
+          prio state. */
+       if (vdev->prio == NULL)
+               vdev->prio = &vdev->v4l2_dev->prio;
 
        /* Part 2: find a free minor, device node number and device index. */
 #ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
@@ -896,8 +893,7 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
        /* Part 4: register the device with sysfs */
        vdev->dev.class = &video_class;
        vdev->dev.devt = MKDEV(VIDEO_MAJOR, vdev->minor);
-       if (vdev->parent)
-               vdev->dev.parent = vdev->parent;
+       vdev->dev.parent = vdev->dev_parent;
        dev_set_name(&vdev->dev, "%s%d", name_base, vdev->num);
        ret = device_register(&vdev->dev);
        if (ret < 0) {
index c9d9f01d21bc8d0f7ce454caa10f6964e3bd5379..68e6b5e912ff6221a0c6ca04231e3e4925f806ff 100644 (file)
@@ -1813,12 +1813,7 @@ static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops *ops,
                        p->flags |= V4L2_CHIP_FL_WRITABLE;
                if (ops->vidioc_g_register)
                        p->flags |= V4L2_CHIP_FL_READABLE;
-               if (vfd->v4l2_dev)
-                       strlcpy(p->name, vfd->v4l2_dev->name, sizeof(p->name));
-               else if (vfd->parent)
-                       strlcpy(p->name, vfd->parent->driver->name, sizeof(p->name));
-               else
-                       strlcpy(p->name, "bridge", sizeof(p->name));
+               strlcpy(p->name, vfd->v4l2_dev->name, sizeof(p->name));
                if (ops->vidioc_g_chip_info)
                        return ops->vidioc_g_chip_info(file, fh, arg);
                if (p->match.addr)
index b2c3776a1cfff2401d3a55656e2e9a6d037f9bcb..c768c9f8abc2ca0f1125cf7c1ce9135587bbefbc 100644 (file)
@@ -96,9 +96,9 @@ struct video_device
        struct device dev;              /* v4l device */
        struct cdev *cdev;              /* character device */
 
-       /* Set either parent or v4l2_dev if your driver uses v4l2_device */
-       struct device *parent;          /* device parent */
        struct v4l2_device *v4l2_dev;   /* v4l2_device parent */
+       /* Only set parent if that can't be deduced from v4l2_dev */
+       struct device *dev_parent;      /* device parent */
 
        /* Control handler associated with this device node. May be NULL. */
        struct v4l2_ctrl_handler *ctrl_handler;