mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil-cisco@xs4all.nl>
To: Ricardo Ribalda <ribalda@chromium.org>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	tfiga@chromium.org
Subject: Re: [PATCH v7 13/17] media: uvcvideo: Return -EACCES to inactive controls
Date: Fri, 19 Mar 2021 10:10:03 +0100	[thread overview]
Message-ID: <21b313b4-dbdf-c1bd-450d-723c601cb61a@xs4all.nl> (raw)
In-Reply-To: <20210318202928.166955-14-ribalda@chromium.org>

On 18/03/2021 21:29, Ricardo Ribalda wrote:
> If a control is inactive return -EACCES to let the userspace know that
> the value will not be applied automatically when the control is active
> again.
> 
> Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
> Suggested-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> ---
>  drivers/media/usb/uvc/uvc_ctrl.c | 68 ++++++++++++++++++++++----------
>  drivers/media/usb/uvc/uvc_v4l2.c | 11 +++++-
>  drivers/media/usb/uvc/uvcvideo.h |  2 +-
>  3 files changed, 58 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
> index 24fd5afc4e4f..1ec8333811bc 100644
> --- a/drivers/media/usb/uvc/uvc_ctrl.c
> +++ b/drivers/media/usb/uvc/uvc_ctrl.c
> @@ -1046,8 +1046,33 @@ static int uvc_query_v4l2_class(struct uvc_video_chain *chain, u32 req_id,
>  	return 0;
>  }
>  
> +static bool uvc_ctrl_is_inactive(struct uvc_video_chain *chain,
> +				 struct uvc_control *ctrl,
> +				 struct uvc_control_mapping *mapping)
> +{
> +	struct uvc_control_mapping *master_map = NULL;
> +	struct uvc_control *master_ctrl = NULL;
> +	s32 val;
> +	int ret;
> +
> +	if (!mapping->master_id)
> +		return false;
> +
> +	__uvc_find_control(ctrl->entity, mapping->master_id, &master_map,
> +			   &master_ctrl, 0);
> +
> +	if (!master_ctrl || !(master_ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR))
> +		return false;
> +
> +	ret = __uvc_ctrl_get(chain, master_ctrl, master_map, &val);
> +	if (ret < 0 || val == mapping->master_manual)
> +		return false;
> +
> +	return true;
> +}

This doesn't work. The problem is that you need to test the new value for the
master control against master_manual, and you are testing against the old value.

So for my uvc camera I have this situation after boot:

                  auto_exposure 0x009a0901 (menu)   : min=0 max=3 default=3 value=3 (Aperture Priority Mode)
                                1: Manual Mode
                                3: Aperture Priority Mode
         exposure_time_absolute 0x009a0902 (int)    : min=3 max=2047 step=1 default=250 value=250 flags=inactive

But trying to change both auto_exposure to manual AND set the new exposure_time_absolute
will fail:

$ v4l2-ctl -c auto_exposure=1,exposure_time_absolute=251
VIDIOC_S_EXT_CTRLS: failed: Permission denied
Error setting controls: Permission denied

This works though with the uvc driver as is currently in the kernel.

Unfortunately, this is not something that is explicitly tested in v4l2-compliance.

Regards,

	Hans

> +
>  int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id,
> -			   bool read)
> +			   unsigned long ioctl)
>  {
>  	struct uvc_control_mapping *mapping;
>  	struct uvc_control *ctrl;
> @@ -1059,11 +1084,26 @@ int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id,
>  	if (!ctrl)
>  		return -EINVAL;
>  
> -	if (!(ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR) && read)
> -		return -EACCES;
> -
> -	if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR) && !read)
> -		return -EACCES;
> +	switch (ioctl) {
> +	case VIDIOC_G_CTRL:
> +	case VIDIOC_G_EXT_CTRLS:
> +		if (!(ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR))
> +			return -EACCES;
> +		break;
> +	case VIDIOC_S_EXT_CTRLS:
> +	case VIDIOC_S_CTRL:
> +		if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR))
> +			return -EACCES;
> +		if (uvc_ctrl_is_inactive(chain, ctrl, mapping))
> +			return -EACCES;
> +		break;
> +	case VIDIOC_TRY_EXT_CTRLS:
> +		if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR))
> +			return -EACCES;
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
>  
>  	return 0;
>  }
> @@ -1087,8 +1127,6 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
>  	struct uvc_control_mapping *mapping,
>  	struct v4l2_queryctrl *v4l2_ctrl)
>  {
> -	struct uvc_control_mapping *master_map = NULL;
> -	struct uvc_control *master_ctrl = NULL;
>  	const struct uvc_menu_info *menu;
>  	unsigned int i;
>  
> @@ -1104,18 +1142,8 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
>  	if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR))
>  		v4l2_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
>  
> -	if (mapping->master_id)
> -		__uvc_find_control(ctrl->entity, mapping->master_id,
> -				   &master_map, &master_ctrl, 0);
> -	if (master_ctrl && (master_ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR)) {
> -		s32 val;
> -		int ret = __uvc_ctrl_get(chain, master_ctrl, master_map, &val);
> -		if (ret < 0)
> -			return ret;
> -
> -		if (val != mapping->master_manual)
> -				v4l2_ctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
> -	}
> +	if (uvc_ctrl_is_inactive(chain, ctrl, mapping))
> +		v4l2_ctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
>  
>  	if (!ctrl->cached) {
>  		int ret = uvc_ctrl_populate_cache(chain, ctrl);
> diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
> index fbb99f3c2fb4..ddebdeb5a81b 100644
> --- a/drivers/media/usb/uvc/uvc_v4l2.c
> +++ b/drivers/media/usb/uvc/uvc_v4l2.c
> @@ -999,6 +999,10 @@ static int uvc_ioctl_g_ctrl(struct file *file, void *fh,
>  	struct v4l2_ext_control xctrl;
>  	int ret;
>  
> +	ret = uvc_ctrl_is_accessible(chain, ctrl->id, VIDIOC_G_CTRL);
> +	if (ret)
> +		return ret;
> +
>  	memset(&xctrl, 0, sizeof(xctrl));
>  	xctrl.id = ctrl->id;
>  
> @@ -1023,6 +1027,10 @@ static int uvc_ioctl_s_ctrl(struct file *file, void *fh,
>  	struct v4l2_ext_control xctrl;
>  	int ret;
>  
> +	ret = uvc_ctrl_is_accessible(chain, ctrl->id, VIDIOC_S_CTRL);
> +	if (ret)
> +		return ret;
> +
>  	memset(&xctrl, 0, sizeof(xctrl));
>  	xctrl.id = ctrl->id;
>  	xctrl.value = ctrl->value;
> @@ -1054,8 +1062,7 @@ static int uvc_ctrl_check_access(struct uvc_video_chain *chain,
>  	int ret = 0;
>  
>  	for (i = 0; i < ctrls->count; ++ctrl, ++i) {
> -		ret = uvc_ctrl_is_accessible(chain, ctrl->id,
> -					    ioctl == VIDIOC_G_EXT_CTRLS);
> +		ret = uvc_ctrl_is_accessible(chain, ctrl->id, ioctl);
>  		if (ret)
>  			break;
>  	}
> diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
> index 9471c342a310..a93aeedb5499 100644
> --- a/drivers/media/usb/uvc/uvcvideo.h
> +++ b/drivers/media/usb/uvc/uvcvideo.h
> @@ -903,7 +903,7 @@ static inline int uvc_ctrl_rollback(struct uvc_fh *handle)
>  int uvc_ctrl_get(struct uvc_video_chain *chain, struct v4l2_ext_control *xctrl);
>  int uvc_ctrl_set(struct uvc_fh *handle, struct v4l2_ext_control *xctrl);
>  int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id,
> -			   bool read);
> +			   unsigned long ioctl);
>  
>  int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
>  		      struct uvc_xu_control_query *xqry);
> 


  reply	other threads:[~2021-03-19  9:11 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-18 20:29 [PATCH v7 00/17] uvcvideo: Fix v4l2-compliance errors Ricardo Ribalda
2021-03-18 20:29 ` [PATCH v7 01/17] media: v4l2-ioctl: Fix check_ext_ctrls Ricardo Ribalda
2021-03-19  9:02   ` Hans Verkuil
2021-03-18 20:29 ` [PATCH v7 02/17] media: pvrusb2: Do not check for V4L2_CTRL_WHICH_DEF_VAL Ricardo Ribalda
2021-03-18 20:29 ` [PATCH v7 03/17] media: uvcvideo: " Ricardo Ribalda
2021-03-18 20:29 ` [PATCH v7 04/17] media: uvcvideo: Set capability in s_param Ricardo Ribalda
2021-03-18 20:29 ` [PATCH v7 05/17] media: uvcvideo: Return -EIO for control errors Ricardo Ribalda
2021-03-18 20:29 ` [PATCH v7 06/17] media: uvcvideo: refactor __uvc_ctrl_add_mapping Ricardo Ribalda
2021-03-18 20:29 ` [PATCH v7 07/17] media: uvcvideo: Add support for V4L2_CTRL_TYPE_CTRL_CLASS Ricardo Ribalda
2021-03-19  7:46   ` Hans Verkuil
2021-03-18 20:29 ` [PATCH v7 08/17] media: uvcvideo: Use dev->name for querycap() Ricardo Ribalda
2021-03-18 20:29 ` [PATCH v7 09/17] media: uvcvideo: Set unique vdev name based in type Ricardo Ribalda
2021-03-18 20:29 ` [PATCH v7 10/17] media: uvcvideo: Increase the size of UVC_METADATA_BUF_SIZE Ricardo Ribalda
2021-03-18 20:29 ` [PATCH v7 11/17] media: uvcvideo: Use control names from framework Ricardo Ribalda
2021-03-18 20:29 ` [PATCH v7 12/17] media: uvcvideo: Check controls flags before accessing them Ricardo Ribalda
2021-03-18 20:29 ` [PATCH v7 13/17] media: uvcvideo: Return -EACCES to inactive controls Ricardo Ribalda
2021-03-19  9:10   ` Hans Verkuil [this message]
2021-03-19  9:49     ` Ricardo Ribalda
2021-03-19 13:40       ` Hans Verkuil
2021-03-18 20:29 ` [PATCH v7 14/17] media: docs: Document the behaviour of uvcdriver Ricardo Ribalda
2021-03-18 20:29 ` [PATCH v7 15/17] media: uvcvideo: Refactor __uvc_ctrl_commit Ricardo Ribalda
2021-03-19  8:33   ` Hans Verkuil
2021-03-19 15:01     ` Ricardo Ribalda Delgado
2021-03-18 20:29 ` [PATCH v7 16/17] media: uvcvideo: Set error_idx during ctrl_commit errors Ricardo Ribalda
2021-03-18 20:29 ` [PATCH v7 17/17] uvc: use vb2 ioctl and fop helpers Ricardo Ribalda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=21b313b4-dbdf-c1bd-450d-723c601cb61a@xs4all.nl \
    --to=hverkuil-cisco@xs4all.nl \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=ribalda@chromium.org \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=tfiga@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®