media: v4l2-dev: Check that g/s_selection are valid before selecting crop
PATCH 1/1 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.
--- drivers/media/v4l2-core/v4l2-dev.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/media/v4l2-core/v4l2-dev.c +4 -2
@@ -642,11 +642,13 @@ static void determine_valid_ioctls(struct video_device *vdev)SET_VALID_IOCTL (ops,VIDIOC_TRY_DECODER_CMD , vidioc_try_decoder_cmd);SET_VALID_IOCTL (ops,VIDIOC_ENUM_FRAMESIZES , vidioc_enum_framesizes);SET_VALID_IOCTL (ops,VIDIOC_ENUM_FRAMEINTERVALS , vidioc_enum_frameintervals); -if (ops->vidioc_g_selection) { +if (ops->vidioc_g_selection && + !test_bit (_IOC_NR (VIDIOC_G_SELECTION ), vdev->valid_ioctls)) {__set_bit (_IOC_NR (VIDIOC_G_CROP ), valid_ioctls);__set_bit (_IOC_NR (VIDIOC_CROPCAP ), valid_ioctls); } -if (ops->vidioc_s_selection) +if (ops->vidioc_s_selection && + !test_bit (_IOC_NR (VIDIOC_S_SELECTION ), vdev->valid_ioctls))__set_bit (_IOC_NR (VIDIOC_S_CROP ), valid_ioctls);SET_VALID_IOCTL (ops,VIDIOC_G_SELECTION , vidioc_g_selection);SET_VALID_IOCTL (ops,VIDIOC_S_SELECTION , vidioc_s_selection);
Signature · 1 line
2.42.0
Le mardi 07 novembre 2023 à 21:05 +0100, Paul Kocialkowski a écrit :
Quoted 8 lines
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.
Quoted 7 lines
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_ioctlwill set the bits. Their meaning will be reversed at the end of the function.Signed-off-by Paul Kocialkowski <[email protected]>
Quoted 24 lines
--- drivers/media/v4l2-core/v4l2-dev.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/media/v4l2-core/v4l2-dev.c +4
-2@@ -642,11 +642,13 @@ static void determine_valid_ioctls(struct video_device *vdev)SET_VALID_IOCTL (ops,VIDIOC_TRY_DECODER_CMD , vidioc_try_decoder_cmd);SET_VALID_IOCTL (ops,VIDIOC_ENUM_FRAMESIZES , vidioc_enum_framesizes);SET_VALID_IOCTL (ops,VIDIOC_ENUM_FRAMEINTERVALS , vidioc_enum_frameintervals); -if (ops->vidioc_g_selection) { +if (ops->vidioc_g_selection && + !test_bit (_IOC_NR (VIDIOC_G_SELECTION ), vdev->valid_ioctls)) {__set_bit (_IOC_NR (VIDIOC_G_CROP ), valid_ioctls);__set_bit (_IOC_NR (VIDIOC_CROPCAP ), valid_ioctls); } -if (ops->vidioc_s_selection) +if (ops->vidioc_s_selection && + !test_bit (_IOC_NR (VIDIOC_S_SELECTION ), vdev->valid_ioctls))__set_bit (_IOC_NR (VIDIOC_S_CROP ), valid_ioctls);SET_VALID_IOCTL (ops,VIDIOC_G_SELECTION , vidioc_g_selection);SET_VALID_IOCTL (ops,VIDIOC_S_SELECTION , vidioc_s_selection);