Skip to content

Commit 1c1d86a

Browse files
Hans VerkuilMauro Carvalho Chehab
Hans Verkuil
authored and
Mauro Carvalho Chehab
committed
[media] v4l2: always require v4l2_dev, rename parent to dev_parent
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 <[email protected]> Acked-by: Sakari Ailus <[email protected]> Acked-by: Laurent Pinchart <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent d481c58 commit 1c1d86a

File tree

3 files changed

+18
-27
lines changed

3 files changed

+18
-27
lines changed

drivers/media/v4l2-core/v4l2-dev.c

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,8 @@ static const struct file_operations v4l2_fops = {
495495
};
496496

497497
/**
498-
* get_index - assign stream index number based on parent device
499-
* @vdev: video_device to assign index number to, vdev->parent should be assigned
498+
* get_index - assign stream index number based on v4l2_dev
499+
* @vdev: video_device to assign index number to, vdev->v4l2_dev should be assigned
500500
*
501501
* Note that when this is called the new device has not yet been registered
502502
* 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)
514514
static DECLARE_BITMAP(used, VIDEO_NUM_DEVICES);
515515
int i;
516516

517-
/* Some drivers do not set the parent. In that case always return 0. */
518-
if (vdev->parent == NULL)
519-
return 0;
520-
521517
bitmap_zero(used, VIDEO_NUM_DEVICES);
522518

523519
for (i = 0; i < VIDEO_NUM_DEVICES; i++) {
524520
if (video_device[i] != NULL &&
525-
video_device[i]->parent == vdev->parent) {
521+
video_device[i]->v4l2_dev == vdev->v4l2_dev) {
526522
set_bit(video_device[i]->index, used);
527523
}
528524
}
@@ -775,6 +771,9 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
775771
/* the release callback MUST be present */
776772
if (WARN_ON(!vdev->release))
777773
return -EINVAL;
774+
/* the v4l2_dev pointer MUST be present */
775+
if (WARN_ON(!vdev->v4l2_dev))
776+
return -EINVAL;
778777

779778
/* v4l2_fh support */
780779
spin_lock_init(&vdev->fh_lock);
@@ -802,16 +801,14 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
802801

803802
vdev->vfl_type = type;
804803
vdev->cdev = NULL;
805-
if (vdev->v4l2_dev) {
806-
if (vdev->v4l2_dev->dev)
807-
vdev->parent = vdev->v4l2_dev->dev;
808-
if (vdev->ctrl_handler == NULL)
809-
vdev->ctrl_handler = vdev->v4l2_dev->ctrl_handler;
810-
/* If the prio state pointer is NULL, then use the v4l2_device
811-
prio state. */
812-
if (vdev->prio == NULL)
813-
vdev->prio = &vdev->v4l2_dev->prio;
814-
}
804+
if (vdev->dev_parent == NULL)
805+
vdev->dev_parent = vdev->v4l2_dev->dev;
806+
if (vdev->ctrl_handler == NULL)
807+
vdev->ctrl_handler = vdev->v4l2_dev->ctrl_handler;
808+
/* If the prio state pointer is NULL, then use the v4l2_device
809+
prio state. */
810+
if (vdev->prio == NULL)
811+
vdev->prio = &vdev->v4l2_dev->prio;
815812

816813
/* Part 2: find a free minor, device node number and device index. */
817814
#ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
@@ -896,8 +893,7 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
896893
/* Part 4: register the device with sysfs */
897894
vdev->dev.class = &video_class;
898895
vdev->dev.devt = MKDEV(VIDEO_MAJOR, vdev->minor);
899-
if (vdev->parent)
900-
vdev->dev.parent = vdev->parent;
896+
vdev->dev.parent = vdev->dev_parent;
901897
dev_set_name(&vdev->dev, "%s%d", name_base, vdev->num);
902898
ret = device_register(&vdev->dev);
903899
if (ret < 0) {

drivers/media/v4l2-core/v4l2-ioctl.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,12 +1813,7 @@ static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops *ops,
18131813
p->flags |= V4L2_CHIP_FL_WRITABLE;
18141814
if (ops->vidioc_g_register)
18151815
p->flags |= V4L2_CHIP_FL_READABLE;
1816-
if (vfd->v4l2_dev)
1817-
strlcpy(p->name, vfd->v4l2_dev->name, sizeof(p->name));
1818-
else if (vfd->parent)
1819-
strlcpy(p->name, vfd->parent->driver->name, sizeof(p->name));
1820-
else
1821-
strlcpy(p->name, "bridge", sizeof(p->name));
1816+
strlcpy(p->name, vfd->v4l2_dev->name, sizeof(p->name));
18221817
if (ops->vidioc_g_chip_info)
18231818
return ops->vidioc_g_chip_info(file, fh, arg);
18241819
if (p->match.addr)

include/media/v4l2-dev.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ struct video_device
9696
struct device dev; /* v4l device */
9797
struct cdev *cdev; /* character device */
9898

99-
/* Set either parent or v4l2_dev if your driver uses v4l2_device */
100-
struct device *parent; /* device parent */
10199
struct v4l2_device *v4l2_dev; /* v4l2_device parent */
100+
/* Only set parent if that can't be deduced from v4l2_dev */
101+
struct device *dev_parent; /* device parent */
102102

103103
/* Control handler associated with this device node. May be NULL. */
104104
struct v4l2_ctrl_handler *ctrl_handler;

0 commit comments

Comments
 (0)