Skip to content

Commit

Permalink
media: v4l2-dev/ioctl: require non-zero device_caps, verify sane quer…
Browse files Browse the repository at this point in the history
…ycap results

Now that all V4L2 drivers set device_caps in struct video_device, we can add
a check for this to ensure all future drivers fill this in.

Also verify that when the querycap ioctl is called the driver didn't mess
with the device_caps value and that capabilities is a superset of device_caps.

Signed-off-by: Hans Verkuil <[email protected]>
Reviewed-by: Sakari Ailus <[email protected]>
[[email protected]: fix too-long line]
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
Hans Verkuil authored and mchehab committed Jul 25, 2019
1 parent 08aac0e commit 3c13505
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
3 changes: 3 additions & 0 deletions drivers/media/v4l2-core/v4l2-dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,9 @@ int __video_register_device(struct video_device *vdev,
/* the v4l2_dev pointer MUST be present */
if (WARN_ON(!vdev->v4l2_dev))
return -EINVAL;
/* the device_caps field MUST be set */
if (WARN_ON(!vdev->device_caps))
return -EINVAL;

/* v4l2_fh support */
spin_lock_init(&vdev->fh_lock);
Expand Down
17 changes: 11 additions & 6 deletions drivers/media/v4l2-core/v4l2-ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1057,14 +1057,19 @@ static int v4l_querycap(const struct v4l2_ioctl_ops *ops,

ret = ops->vidioc_querycap(file, fh, cap);

cap->capabilities |= V4L2_CAP_EXT_PIX_FORMAT;
/*
* Drivers MUST fill in device_caps, so check for this and
* warn if it was forgotten.
* Drivers must not change device_caps, so check for this and
* warn if this happened.
*/
WARN_ON(cap->device_caps != vfd->device_caps);
/*
* Check that capabilities is a superset of
* vfd->device_caps | V4L2_CAP_DEVICE_CAPS
*/
WARN(!(cap->capabilities & V4L2_CAP_DEVICE_CAPS) ||
!cap->device_caps, "Bad caps for driver %s, %x %x",
cap->driver, cap->capabilities, cap->device_caps);
WARN_ON((cap->capabilities &
(vfd->device_caps | V4L2_CAP_DEVICE_CAPS)) !=
(vfd->device_caps | V4L2_CAP_DEVICE_CAPS));
cap->capabilities |= V4L2_CAP_EXT_PIX_FORMAT;
cap->device_caps |= V4L2_CAP_EXT_PIX_FORMAT;

return ret;
Expand Down

0 comments on commit 3c13505

Please sign in to comment.