Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: v4l2-dev: Check that g/s_selection are valid before selecting crop

The cropcap and g/s_crop ioctls are automatically marked as valid whenever
the g/s_selection ops are filled. The rationale is to auto-enable these
legacy cropcap and g/s_crop ioctls that rely on g/s_selection.

However it's possible that the ops are filled but explicitly disabled with
calls to v4l2_disable_ioctl. In this situation the legacy ioctls should not
be enabled.

Add a check on the video device's valid ioctls field before auto-selecting
them to honor the driver's choice. Note that the meaning of the bitfield
stored in the video device is the opposite of what the name suggests as
v4l2_disable_ioctl will set the bits. Their meaning will be reversed at
the end of the function.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>

authored by

Paul Kocialkowski and committed by
Mauro Carvalho Chehab
dd4229fa 57e3f1cf

+4 -2
+4 -2
drivers/media/v4l2-core/v4l2-dev.c
··· 642 642 SET_VALID_IOCTL(ops, VIDIOC_TRY_DECODER_CMD, vidioc_try_decoder_cmd); 643 643 SET_VALID_IOCTL(ops, VIDIOC_ENUM_FRAMESIZES, vidioc_enum_framesizes); 644 644 SET_VALID_IOCTL(ops, VIDIOC_ENUM_FRAMEINTERVALS, vidioc_enum_frameintervals); 645 - if (ops->vidioc_g_selection) { 645 + if (ops->vidioc_g_selection && 646 + !test_bit(_IOC_NR(VIDIOC_G_SELECTION), vdev->valid_ioctls)) { 646 647 __set_bit(_IOC_NR(VIDIOC_G_CROP), valid_ioctls); 647 648 __set_bit(_IOC_NR(VIDIOC_CROPCAP), valid_ioctls); 648 649 } 649 - if (ops->vidioc_s_selection) 650 + if (ops->vidioc_s_selection && 651 + !test_bit(_IOC_NR(VIDIOC_S_SELECTION), vdev->valid_ioctls)) 650 652 __set_bit(_IOC_NR(VIDIOC_S_CROP), valid_ioctls); 651 653 SET_VALID_IOCTL(ops, VIDIOC_G_SELECTION, vidioc_g_selection); 652 654 SET_VALID_IOCTL(ops, VIDIOC_S_SELECTION, vidioc_s_selection);