Linux Media Controller development
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Ricardo Ribalda <ribalda@chromium.org>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	tfiga@chromium.org, senozhatsky@chromium.org, yunkec@google.com
Subject: Re: [PATCH v7 2/8] media: uvcvideo: Add support for per-device control mapping overrides
Date: Fri, 17 Jun 2022 16:44:02 +0300	[thread overview]
Message-ID: <YqyFIq8iv/FZ6tNe@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20220617103645.71560-3-ribalda@chromium.org>

Hi Ricardo,

Thank you for the patch.

On Fri, Jun 17, 2022 at 12:36:39PM +0200, Ricardo Ribalda wrote:
> Some devices do not implement all their controls in a way that complies
> with the UVC specification. This is for instance the case for several
> devices that do not support the disabled mode for the power line
> frequency control. Add a mechanism to allow per-device control mapping
> overrides to avoid errors when accessing non-compliant controls.
> 
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  drivers/media/usb/uvc/uvc_ctrl.c | 35 ++++++++++++++++++++++++++------
>  drivers/media/usb/uvc/uvcvideo.h |  1 +
>  2 files changed, 30 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
> index a709ebbb4d69..092decfdaa62 100644
> --- a/drivers/media/usb/uvc/uvc_ctrl.c
> +++ b/drivers/media/usb/uvc/uvc_ctrl.c
> @@ -2403,9 +2403,8 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,
>  {
>  	const struct uvc_control_info *info = uvc_ctrls;
>  	const struct uvc_control_info *iend = info + ARRAY_SIZE(uvc_ctrls);
> -	const struct uvc_control_mapping *mapping = uvc_ctrl_mappings;
> -	const struct uvc_control_mapping *mend =
> -		mapping + ARRAY_SIZE(uvc_ctrl_mappings);
> +	const struct uvc_control_mapping *mapping;
> +	const struct uvc_control_mapping *mend;
>  
>  	/* XU controls initialization requires querying the device for control
>  	 * information. As some buggy UVC devices will crash when queried
> @@ -2433,14 +2432,38 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,
>  	if (!ctrl->initialized)
>  		return;
>  
> -	/* Process common mappings first. */
> -	for (; mapping < mend; ++mapping) {
> +	/*
> +	 * First check if the device provides a custom mapping for this control,
> +	 * used to override standard mappings for non-conformant devices. Don't
> +	 * process standard mappings if a custom mapping is found. This
> +	 * mechanism doesn't support combining standard and custom mappings for
> +	 * a single control.
> +	 */
> +	if (chain->dev->info->mappings) {
> +		bool custom = false;
> +		unsigned int i;
> +
> +		for (i = 0; (mapping = chain->dev->info->mappings[i]); ++i) {
> +			if (uvc_entity_match_guid(ctrl->entity, mapping->entity) &&
> +			    ctrl->info.selector == mapping->selector) {
> +				__uvc_ctrl_add_mapping(chain, ctrl, mapping);
> +				custom = true;
> +			}
> +		}
> +
> +		if (custom)
> +			return;
> +	}
> +
> +	/* Process common mappings next. */
> +	mend = mapping + ARRAY_SIZE(uvc_ctrl_mappings);

I don't think mapping has the right value here, it could even be
uninitialized. Let's make this

	mapping = uvc_ctrl_mappings;
	mend = mapping + ARRAY_SIZE(uvc_ctrl_mappings);

	for (; mapping < mend; ++mapping) {

to match the code below.

> +	for (mapping = uvc_ctrl_mappings; mapping < mend; ++mapping) {
>  		if (uvc_entity_match_guid(ctrl->entity, mapping->entity) &&
>  		    ctrl->info.selector == mapping->selector)
>  			__uvc_ctrl_add_mapping(chain, ctrl, mapping);
>  	}
>  
> -	/* And then version-specific mappings. */
> +	/* Finally process version-specific mappings. */
>  	if (chain->dev->uvc_version < 0x0150) {
>  		mapping = uvc_ctrl_mappings_uvc11;
>  		mend = mapping + ARRAY_SIZE(uvc_ctrl_mappings_uvc11);
> diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
> index c5b4febd2d94..fff5c5c99a3d 100644
> --- a/drivers/media/usb/uvc/uvcvideo.h
> +++ b/drivers/media/usb/uvc/uvcvideo.h
> @@ -667,6 +667,7 @@ struct uvc_device_info {
>  	u32	quirks;
>  	u32	meta_format;
>  	u16	uvc_version;
> +	const struct uvc_control_mapping **mappings;
>  };
>  
>  struct uvc_device {

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2022-06-17 13:44 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-17 10:36 [PATCH v7 0/8] uvcvideo: Fix handling of power_line_frequency Ricardo Ribalda
2022-06-17 10:36 ` [PATCH v7 1/8] media: uvcvideo: Add missing value for power_line_frequency Ricardo Ribalda
2022-06-17 10:36 ` [PATCH v7 2/8] media: uvcvideo: Add support for per-device control mapping overrides Ricardo Ribalda
2022-06-17 13:44   ` Laurent Pinchart [this message]
2022-06-17 14:07     ` Ricardo Ribalda
2022-06-17 14:40   ` kernel test robot
2022-06-30 11:07   ` Dan Carpenter
2022-06-30 23:16     ` Ricardo Ribalda
2022-07-01  2:31       ` [kbuild-all] " Philip Li
2022-07-01  7:26       ` Dan Carpenter
2022-06-17 10:36 ` [PATCH v7 3/8] media: uvcvideo: Support minimum for V4L2_CTRL_TYPE_MENU Ricardo Ribalda
2022-06-17 13:49   ` Laurent Pinchart
2022-06-17 13:55     ` Ricardo Ribalda
2022-06-17 14:11       ` Laurent Pinchart
2022-06-17 14:15         ` Ricardo Ribalda
2022-06-17 10:36 ` [PATCH v7 4/8] media: uvcvideo: Limit power line control for Quanta UVC Webcam Ricardo Ribalda
2022-06-17 14:01   ` Laurent Pinchart
2022-06-17 14:18     ` Ricardo Ribalda
2022-06-17 10:36 ` [PATCH v7 5/8] media: uvcvideo: Limit power line control for Chicony Easycamera Ricardo Ribalda
2022-06-17 10:36 ` [PATCH v7 6/8] " Ricardo Ribalda
2022-06-17 10:36 ` [PATCH v7 7/8] media: uvcvideo: Limit power line control for Quanta cameras Ricardo Ribalda
2022-06-17 10:36 ` [PATCH v7 8/8] media: uvcvideo: Limit power line control for Acer EasyCamera 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=YqyFIq8iv/FZ6tNe@pendragon.ideasonboard.com \
    --to=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=senozhatsky@chromium.org \
    --cc=tfiga@chromium.org \
    --cc=yunkec@google.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