diff mbox series

[6/8] usb: gadget: uvc: try harder to find a valid format

Message ID 20230323-uvc-gadget-cleanup-v1-6-e41f0c5d9d8e@pengutronix.de
State New
Headers show
Series usb: gadget: uvc: fix errors reported by v4l2-compliance | expand

Commit Message

Michael Tretter March 23, 2023, 11:41 a.m. UTC
The TRY_FMT call should try to avoid returning EINVAL. If the requested
pixelformat is not supported by the driver, the driver should fall back
to it's own default and only then fail the request.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
---
 drivers/usb/gadget/function/uvc_v4l2.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Laurent Pinchart March 24, 2023, 9:35 a.m. UTC | #1
Hi Michael,

Thank you for the patch.

On Thu, Mar 23, 2023 at 12:41:14PM +0100, Michael Tretter wrote:
> The TRY_FMT call should try to avoid returning EINVAL. If the requested
> pixelformat is not supported by the driver, the driver should fall back
> to it's own default and only then fail the request.

It should actually never fail.

You may recall that I didn't like the TRY_FMT implementation, and I
still stand by the arguments I provided by then. If you want to handle
this properly, revert the commits that added format handling to the
driver.

> Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
> ---
>  drivers/usb/gadget/function/uvc_v4l2.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/function/uvc_v4l2.c
> index 3f728f451ed5..c5983bb0a8d1 100644
> --- a/drivers/usb/gadget/function/uvc_v4l2.c
> +++ b/drivers/usb/gadget/function/uvc_v4l2.c
> @@ -317,11 +317,15 @@ uvc_v4l2_try_format(struct file *file, void *fh, struct v4l2_format *fmt)
>  		 fmt->fmt.pix.width, fmt->fmt.pix.height);
>  
>  	uformat = find_format_by_pix(uvc, fmt->fmt.pix.pixelformat);
> +	if (!uformat)
> +		uformat = get_default_format(uvc);
>  	if (!uformat)
>  		return -EINVAL;
>  
>  	uframe = find_closest_frame_by_size(uvc, uformat,
>  				fmt->fmt.pix.width, fmt->fmt.pix.height);
> +	if (!uframe)
> +		uframe = get_default_frame(uvc, uformat);
>  	if (!uframe)
>  		return -EINVAL;
>
diff mbox series

Patch

diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/function/uvc_v4l2.c
index 3f728f451ed5..c5983bb0a8d1 100644
--- a/drivers/usb/gadget/function/uvc_v4l2.c
+++ b/drivers/usb/gadget/function/uvc_v4l2.c
@@ -317,11 +317,15 @@  uvc_v4l2_try_format(struct file *file, void *fh, struct v4l2_format *fmt)
 		 fmt->fmt.pix.width, fmt->fmt.pix.height);
 
 	uformat = find_format_by_pix(uvc, fmt->fmt.pix.pixelformat);
+	if (!uformat)
+		uformat = get_default_format(uvc);
 	if (!uformat)
 		return -EINVAL;
 
 	uframe = find_closest_frame_by_size(uvc, uformat,
 				fmt->fmt.pix.width, fmt->fmt.pix.height);
+	if (!uframe)
+		uframe = get_default_frame(uvc, uformat);
 	if (!uframe)
 		return -EINVAL;