media: uvcvideo: Handle errors from calls to usb_string
authorGuenter Roeck <linux@roeck-us.net>
Tue, 25 Oct 2022 14:41:01 +0000 (16:41 +0200)
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Sun, 15 Jan 2023 21:45:09 +0000 (23:45 +0200)
commit4867bb590ae445bcfaa711a86b603c97e94574b3
treecc773ad31c2df5cf35b9a187280e882b4f7323d7
parent3bc22dc66a4f386393119118169ed0b78c389898
media: uvcvideo: Handle errors from calls to usb_string

On a Webcam from Quanta, we see the following error.

usb 3-5: New USB device found, idVendor=0408, idProduct=30d2, bcdDevice= 0.03
usb 3-5: New USB device strings: Mfr=3, Product=1, SerialNumber=2
usb 3-5: Product: USB2.0 HD UVC WebCam
usb 3-5: Manufacturer: Quanta
usb 3-5: SerialNumber: 0x0001
...
uvcvideo: Found UVC 1.10 device USB2.0 HD UVC WebCam (0408:30d2)
uvcvideo: Failed to initialize entity for entity 5
uvcvideo: Failed to register entities (-22).

The Webcam reports an entity of type UVC_VC_EXTENSION_UNIT. It reports a
string index of '7' associated with that entity. The attempt to read that
string from the camera fails with error -32 (-EPIPE). usb_string() returns
that error, but it is ignored. As result, the entity name is empty. This
later causes v4l2_device_register_subdev() to return -EINVAL, and no
entities are registered as result.

While this appears to be a firmware problem with the camera, the kernel
should still handle the situation gracefully. To do that, check the return
value from usb_string(). If it reports an error, assign the entity's
default name.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
drivers/media/usb/uvc/uvc_driver.c