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 50459f103edf ("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: 50459f103edf ("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>

authored by Laurent Pinchart and committed by Mauro Carvalho Chehab 81f3affa b37a356d

Changed files
+11 -5
drivers
media
usb
+11 -5
drivers/media/usb/uvc/uvc_driver.c
··· 251 251 /* Find the format descriptor from its GUID. */ 252 252 fmtdesc = uvc_format_by_guid(&buffer[5]); 253 253 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 + */ 257 259 dev_info(&streaming->intf->dev, 258 260 "Unknown video format %pUl\n", &buffer[5]); 259 - format->fcc = 0; 261 + return 0; 260 262 } 261 263 264 + format->fcc = fmtdesc->fcc; 262 265 format->bpp = buffer[21]; 263 266 264 267 /* ··· 678 675 interval = (u32 *)&frame[nframes]; 679 676 680 677 streaming->format = format; 681 - streaming->nformats = nformats; 678 + streaming->nformats = 0; 682 679 683 680 /* Parse the format descriptors. */ 684 681 while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE) { ··· 692 689 &interval, buffer, buflen); 693 690 if (ret < 0) 694 691 goto error; 692 + if (!ret) 693 + break; 695 694 695 + streaming->nformats++; 696 696 frame += format->nframes; 697 697 format++; 698 698