From: Hans Verkuil <hverkuil@xs4all.nl>
To: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Cc: Ricardo Ribalda <ribalda@chromium.org>,
Linux Media Mailing List <linux-media@vger.kernel.org>
Subject: Re: [PATCH] uvcvideo: uvc_ctrl_is_accessible: check for INACTIVE
Date: Thu, 25 Mar 2021 13:27:48 +0100 [thread overview]
Message-ID: <ffaa3e0c-9137-91ee-b4e2-e64a3402aff8@xs4all.nl> (raw)
In-Reply-To: <CAPybu_1qv67P6WQqXM6g1qr5=n7PPre3u0TJkkhk0wpWEG7F3Q@mail.gmail.com>
On 23/03/2021 16:29, Ricardo Ribalda Delgado wrote:
> Hi Hans
>
> On Mon, Mar 22, 2021 at 1:06 PM Hans Verkuil <hverkuil@xs4all.nl> wrote:
>>
>> Check for inactive controls in uvc_ctrl_is_accessible().
>> Use the new value for the master_id controls if present,
>> otherwise use the existing value to determine if it is OK
>> to set the control. Doing this here avoids attempting to
>> set an inactive control, which will return an error from the
>> USB device.
>
> Dont you think that this patch is not needed if this is used:
> https://patchwork.linuxtv.org/project/linux-media/patch/20210319170906.278238-17-ribalda@chromium.org/
> ?
That might well be the case :-)
I haven't really looked at that.
>
>
> Also Maybe it is wrong. (Maybe it is the keyword here ;).
> I think the initial assumption was that uvc_ctrl_is_accessible shall
> not access the hardware, but with this patch it is accessing it.
It's only accessing it if master_ctrl->loaded is 0 (see __uvc_ctrl_get()).
If loaded is 0, and __uvc_ctrl_get() returns an error, then that error is
ignored and the code will assume that the control is accessible.
Note that what we try to avoid is *setting* an inactive control. In this
case we're reading the master control, which should be safe except for
USB hardware problems that can return an error.
Regards,
Hans
>>
>> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
>> ---
>> Ricardo: this can be added to your uvc series. It avoids attempts to set
>> inactive controls.
>> ---
>> drivers/media/usb/uvc/uvc_ctrl.c | 28 +++++++++++++++++++++++++++-
>> drivers/media/usb/uvc/uvc_v4l2.c | 4 ++--
>> drivers/media/usb/uvc/uvcvideo.h | 3 ++-
>> 3 files changed, 31 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
>> index d9d4add1e813..6e7b904bc33d 100644
>> --- a/drivers/media/usb/uvc/uvc_ctrl.c
>> +++ b/drivers/media/usb/uvc/uvc_ctrl.c
>> @@ -1047,10 +1047,18 @@ static int uvc_query_v4l2_class(struct uvc_video_chain *chain, u32 req_id,
>> }
>>
>> int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id,
>> - bool read)
>> + const struct v4l2_ext_controls *ctrls,
>> + unsigned long ioctl)
>> {
>> + struct uvc_control_mapping *master_map = NULL;
>> + struct uvc_control *master_ctrl = NULL;
>> struct uvc_control_mapping *mapping;
>> struct uvc_control *ctrl;
>> + bool read = ioctl == VIDIOC_G_EXT_CTRLS;
>> + bool try = ioctl == VIDIOC_TRY_EXT_CTRLS;
>> + s32 val;
>> + int ret;
>> + int i;
>>
>> if (__uvc_query_v4l2_class(chain, v4l2_id, 0) >= 0)
>> return -EACCES;
>> @@ -1065,6 +1073,24 @@ int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id,
>> if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR) && !read)
>> return -EACCES;
>>
>> + if (read || try || !mapping->master_id)
>> + return 0;
>> +
>> + for (i = ctrls->count - 1; i >= 0; i--)
>> + if (ctrls->controls[i].id == mapping->master_id)
>> + return ctrls->controls[i].value ==
>> + mapping->master_manual ? 0 : -EACCES;
>> +
>> + __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 0;
>> +
>> + ret = __uvc_ctrl_get(chain, master_ctrl, master_map, &val);
>> + if (ret >= 0 && val != mapping->master_manual)
>> + return -EACCES;
>> +
>> return 0;
>> }
>>
>> diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
>> index 12362e0f9870..e40db7ae18b1 100644
>> --- a/drivers/media/usb/uvc/uvc_v4l2.c
>> +++ b/drivers/media/usb/uvc/uvc_v4l2.c
>> @@ -803,8 +803,8 @@ 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, ctrls,
>> + ioctl);
>> if (ret)
>> break;
>> }
>> diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
>> index aedb4d3d4db9..8849d7953767 100644
>> --- a/drivers/media/usb/uvc/uvcvideo.h
>> +++ b/drivers/media/usb/uvc/uvcvideo.h
>> @@ -869,7 +869,8 @@ 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);
>> + const struct v4l2_ext_controls *ctrls,
>> + unsigned long ioctl);
>>
>> int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
>> struct uvc_xu_control_query *xqry);
>> --
>> 2.30.0
>>
>>
>
>
next prev parent reply other threads:[~2021-03-25 12:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-22 12:04 [PATCH] uvcvideo: uvc_ctrl_is_accessible: check for INACTIVE Hans Verkuil
2021-03-23 15:29 ` Ricardo Ribalda Delgado
2021-03-25 12:27 ` Hans Verkuil [this message]
2021-03-25 14:02 ` 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=ffaa3e0c-9137-91ee-b4e2-e64a3402aff8@xs4all.nl \
--to=hverkuil@xs4all.nl \
--cc=linux-media@vger.kernel.org \
--cc=ribalda@chromium.org \
--cc=ricardo.ribalda@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).