Some devices, namely the DJI Osmo Pocket 4P (2ca3:0023), set bVariableSize to 0 which fails to identify the HEVC format as compressed. Due to this, the driver sets the buffer size to 0, making the format unusable. Add a new heuristic that automatically sets the UVC_FMT_FLAG_COMPRESSED flag for compressed formats and publicly warns about the non-compliant devices. Fixes: 40b222b56ea8 ("media: uvcvideo: Add mapping for HEVC payloads") Cc: stable@vger.kernel.org Reported-by: Jordan Moormann Closes: https://lore.kernel.org/linux-media/c2c00ad1-b21c-42f9-b3a1-e03a0ad49651@jordan-systems.de Link: https://lore.kernel.org/linux-media/c2c00ad1-b21c-42f9-b3a1-e03a0ad49651@jordan-systems.de # USB descriptor for DJI cam Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_driver.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index cbc14569716b..f5446fc8100d 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -332,6 +332,18 @@ static int uvc_parse_frame(struct uvc_device *dev, return buffer[0]; } +static bool uvc_format_is_compressed(u32 fcc) +{ + switch (fcc) { + case V4L2_PIX_FMT_H264: + case V4L2_PIX_FMT_HEVC: + case V4L2_PIX_FMT_MJPEG: + return true; + default: + return false; + } +} + static int uvc_parse_format(struct uvc_device *dev, struct uvc_streaming *streaming, struct uvc_format *format, struct uvc_frame *frames, u32 **intervals, const unsigned char *buffer, @@ -413,8 +425,14 @@ static int uvc_parse_format(struct uvc_device *dev, ftype = UVC_VS_FRAME_UNCOMPRESSED; } else { ftype = UVC_VS_FRAME_FRAME_BASED; - if (buffer[27]) + if (buffer[27]) { + format->flags = UVC_FMT_FLAG_COMPRESSED; + } else if (uvc_format_is_compressed(format->fcc)) { + dev_warn(&streaming->intf->dev, + "UVC non compliance: forcing format %p4cc as compressed\n", + &format->fcc); format->flags = UVC_FMT_FLAG_COMPRESSED; + } } break; -- 2.56.1.708.g77570a6a1d-goog