Skip to content

Commit 81f3aff

Browse files
pinchartlmchehab
authored andcommitted
media: uvcvideo: Don't expose unsupported formats to userspace
When the uvcvideo driver encounters a format descriptor with an unknown format GUID, it creates a corresponding struct uvc_format instance with the fcc field set to 0. Since commit 50459f1 ("media: uvcvideo: Remove format descriptions"), the driver relies on the V4L2 core to provide the format description string, which the V4L2 core can't do without a valid 4CC. This triggers a WARN_ON. As a format with a zero 4CC can't be selected, it is unusable for applications. Ignore the format completely without creating a uvc_format instance, which fixes the warning. Link: https://bugzilla.kernel.org/show_bug.cgi?id=217252 Link: https://bugzilla.redhat.com/show_bug.cgi?id=2180107 Fixes: 50459f1 ("media: uvcvideo: Remove format descriptions") Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Ricardo Ribalda <ribalda@chromium.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
1 parent b37a356 commit 81f3aff

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

drivers/media/usb/uvc/uvc_driver.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,17 @@ static int uvc_parse_format(struct uvc_device *dev,
251251
/* Find the format descriptor from its GUID. */
252252
fmtdesc = uvc_format_by_guid(&buffer[5]);
253253

254-
if (fmtdesc != NULL) {
255-
format->fcc = fmtdesc->fcc;
256-
} else {
254+
if (!fmtdesc) {
255+
/*
256+
* Unknown video formats are not fatal errors, the
257+
* caller will skip this descriptor.
258+
*/
257259
dev_info(&streaming->intf->dev,
258260
"Unknown video format %pUl\n", &buffer[5]);
259-
format->fcc = 0;
261+
return 0;
260262
}
261263

264+
format->fcc = fmtdesc->fcc;
262265
format->bpp = buffer[21];
263266

264267
/*
@@ -675,7 +678,7 @@ static int uvc_parse_streaming(struct uvc_device *dev,
675678
interval = (u32 *)&frame[nframes];
676679

677680
streaming->format = format;
678-
streaming->nformats = nformats;
681+
streaming->nformats = 0;
679682

680683
/* Parse the format descriptors. */
681684
while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE) {
@@ -689,7 +692,10 @@ static int uvc_parse_streaming(struct uvc_device *dev,
689692
&interval, buffer, buflen);
690693
if (ret < 0)
691694
goto error;
695+
if (!ret)
696+
break;
692697

698+
streaming->nformats++;
693699
frame += format->nframes;
694700
format++;
695701

0 commit comments

Comments
 (0)