Re: [PATCH 1/3] media: uvcvideo: Report the failing control when restoring controls fails

From: Ricardo Ribalda

Date: Tue Nov 24 2026 - 14:22:31 EST


Hi Chris

On Tue, 24 Nov 2026 at 11:10, Chris Bainbridge
<chris.bainbridge@xxxxxxxxxxxxx> wrote:
>
> When uvc_ctrl_commit_entity() fails while restoring the controls after a
> USB reset_resume, the only message visible at the default loglevel is
> the generic "reset_resume error -5" from the USB core. The control that
> caused the failure and the reason for it are only visible with the
> uvcvideo trace parameter enabled (UVC_DBG_CONTROL), which makes the
> problem almost impossible to diagnose in the field.
>
> On a Logitech C270 (046d:0825, USB_QUIRK_RESET_RESUME), the processing
> unit restore fails with UVC error code 7 (Invalid Request), mapped to
> -EIO, and the user only sees "reset_resume error -5". The restore order
> suggests that WHITE_BALANCE_TEMPERATURE is written while auto white
> balance is enabled, which the device rejects.
>
> Pass the err_ctrl out parameter of uvc_ctrl_commit_entity() and report
> the name, the selector and the entity id of the failing control,
> together with the error code, using a ratelimited warning. If the
> failing control is not known, report the entity and the error code only.
>
> Also extend the "Control error %u" debug message in uvc_query_ctrl()
> with the name of the UVC error code, the name of the request, the
> selector and the unit, so that the cause of the STALL is visible in the
> trace log.
>
> Signed-off-by: Chris Bainbridge <chris.bainbridge@xxxxxxxxxxxxx>
> ---
> drivers/media/usb/uvc/uvc_ctrl.c | 36 +++++++++++++++++++++++++++++--
> drivers/media/usb/uvc/uvc_video.c | 31 +++++++++++++++++++++++++-
> 2 files changed, 64 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
> index d2f722bc3459..f70fa37800a4 100644
> --- a/drivers/media/usb/uvc/uvc_ctrl.c
> +++ b/drivers/media/usb/uvc/uvc_ctrl.c
> @@ -3199,6 +3199,34 @@ int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
> * Suspend/resume
> */
>
> +/*
> + * Report a failure to restore the controls of an entity. @err_ctrl points to
> + * the control that failed, or is NULL if the failing control is not known.
> + */
> +static void uvc_ctrl_restore_error(struct uvc_device *dev,
> + const struct uvc_entity *entity,
> + struct uvc_control *err_ctrl, int ret)
> +{
> + const struct uvc_control_mapping *mapping;
> + const char *name = "Unknown Control";
> +
> + if (!err_ctrl) {
> + dev_warn_ratelimited(&dev->intf->dev,
> + "Failed to restore controls on unit %u: %d\n",
> + entity->id, ret);
> + return;
> + }
Unless I made a mistake there i no case where err_ctrl can be NULL.

> +
> + mapping = list_first_entry_or_null(&err_ctrl->info.mappings,
> + struct uvc_control_mapping, list);
> + if (mapping)
> + name = uvc_map_get_name(mapping);

can you move this into a function uvc_ctrl_get_first_mapping_name(err_ctrl)

with that move this function would be so small that it is probably a
good idea to squash it into uvc_ctrl_restore_values

> +
> + dev_warn_ratelimited(&dev->intf->dev,
> + "Failed to restore control %s (selector %u on unit %u): %d\n",
> + name, err_ctrl->info.selector, entity->id, ret);
> +}
> +
> /*
> * Restore control values after resume, skipping controls that haven't been
> * changed.
> @@ -3210,6 +3238,7 @@ int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
> */
> int uvc_ctrl_restore_values(struct uvc_device *dev)
> {
> + struct uvc_control *err_ctrl;
please do err_ctrl = NULL here and not in the loop. We probably do
not need it here either, but will make the static analyzer happy.

> struct uvc_control *ctrl;
> struct uvc_entity *entity;
> unsigned int i;
> @@ -3230,9 +3259,12 @@ int uvc_ctrl_restore_values(struct uvc_device *dev)
> ctrl->dirty = 1;
> }
>
> - ret = uvc_ctrl_commit_entity(dev, NULL, entity, 0, NULL);
> - if (ret < 0)
> + err_ctrl = NULL;
> + ret = uvc_ctrl_commit_entity(dev, NULL, entity, 0, &err_ctrl);
> + if (ret < 0) {
> + uvc_ctrl_restore_error(dev, entity, err_ctrl, ret);
> return ret;
> + }
> }
>
> return 0;
> diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> index a92a986ab714..b10064defaf4 100644
> --- a/drivers/media/usb/uvc/uvc_video.c
> +++ b/drivers/media/usb/uvc/uvc_video.c
> @@ -68,6 +68,32 @@ static const char *uvc_query_name(u8 query)
> }
> }
>

Maybe you could make a function

static const char *uvc_ctrl_error_name_code(u8 error, int *code)

and reuse it in uvc_query_ctrl() it is much more nicer to get the
error name than the code

(sorry to treat you like Santa :P)

> +static const char *uvc_error_code_name(u8 error)
> +{
> + switch (error) {
> + case 0:
> + return "No error";
> + case 1:
> + return "Not ready";
> + case 2:
> + return "Wrong state";
> + case 3:
> + return "Power";
> + case 4:
> + return "Out of range";
> + case 5:
> + return "Invalid unit";
> + case 6:
> + return "Invalid control";
> + case 7:
> + return "Invalid request";
> + case 8:
> + return "Invalid value within range";
> + default:
> + return "Unknown";
> + }
> +}
> +
> int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit,
> u8 intfnum, u8 cs, void *data, u16 size)
> {
> @@ -125,7 +151,10 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit,
> return ret < 0 ? ret : -EPIPE;
> }
>
> - uvc_dbg(dev, CONTROL, "Control error %u\n", error);
> + uvc_dbg(dev, CONTROL,
> + "Control error %u (%s) for %s control %u on unit %u\n",
> + error, uvc_error_code_name(error), uvc_query_name(query), cs,
> + unit);
>
> switch (error) {
> case 0:
> --
> 2.53.0
>
>


--
Ricardo Ribalda