]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
usb: gadget: uvc: fix try format returns on uncompressed formats
authorMichael Grzeschik <m.grzeschik@pengutronix.de>
Wed, 21 Feb 2024 22:08:31 +0000 (23:08 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 26 Mar 2024 09:42:03 +0000 (10:42 +0100)
When setting uncompressed formats, the values of bytesperline and
sizeimage can already be determined by using the v4l2_fill_pixfmt helper
function. We change the try_fmt function to use the helper instead.

Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Link: https://lore.kernel.org/r/20240221-uvc-gadget-uncompressed-v1-1-f55e97287cae@pengutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/function/uvc_v4l2.c

index c7e5fa4f29e038e7737bfd13c90ee3a2c577da30..a024aecb76dc370bffdbd00cdc7e3845993029ea 100644 (file)
@@ -260,12 +260,26 @@ uvc_v4l2_try_format(struct file *file, void *fh, struct v4l2_format *fmt)
        if (!uframe)
                return -EINVAL;
 
-       fmt->fmt.pix.width = uframe->frame.w_width;
-       fmt->fmt.pix.height = uframe->frame.w_height;
+       if (uformat->type == UVCG_UNCOMPRESSED) {
+               struct uvcg_uncompressed *u =
+                       to_uvcg_uncompressed(&uformat->group.cg_item);
+               if (!u)
+                       return 0;
+
+               v4l2_fill_pixfmt(&fmt->fmt.pix, fmt->fmt.pix.pixelformat,
+                                uframe->frame.w_width, uframe->frame.w_height);
+
+               if (fmt->fmt.pix.sizeimage != (uvc_v4l2_get_bytesperline(uformat, uframe) *
+                                               uframe->frame.w_height))
+                       return -EINVAL;
+       } else {
+               fmt->fmt.pix.width = uframe->frame.w_width;
+               fmt->fmt.pix.height = uframe->frame.w_height;
+               fmt->fmt.pix.bytesperline = uvc_v4l2_get_bytesperline(uformat, uframe);
+               fmt->fmt.pix.sizeimage = uvc_get_frame_size(uformat, uframe);
+               fmt->fmt.pix.pixelformat = to_uvc_format(uformat)->fcc;
+       }
        fmt->fmt.pix.field = V4L2_FIELD_NONE;
-       fmt->fmt.pix.bytesperline = uvc_v4l2_get_bytesperline(uformat, uframe);
-       fmt->fmt.pix.sizeimage = uvc_get_frame_size(uformat, uframe);
-       fmt->fmt.pix.pixelformat = to_uvc_format(uformat)->fcc;
        fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
        fmt->fmt.pix.priv = 0;