Skip to content

Commit f00ee2c

Browse files
ribaldamchehab
authored andcommitted
media: uvcvideo: Support partial control reads
Some cameras, like the ELMO MX-P3, do not return all the bytes requested from a control if it can fit in less bytes. Eg: Returning 0xab instead of 0x00ab. usb 3-9: Failed to query (GET_DEF) UVC control 3 on unit 2: 1 (exp. 2). Extend the returned value from the camera and return it. Cc: [email protected] Fixes: a763b9f ("media: uvcvideo: Do not return positive errors in uvc_query_ctrl()") Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Ricardo Ribalda <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Hans de Goede <[email protected]> Reviewed-by: Laurent Pinchart <[email protected]> Signed-off-by: Laurent Pinchart <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent c31cffd commit f00ee2c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

drivers/media/usb/uvc/uvc_video.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,27 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit,
7979
if (likely(ret == size))
8080
return 0;
8181

82+
/*
83+
* Some devices return shorter USB control packets than expected if the
84+
* returned value can fit in less bytes. Zero all the bytes that the
85+
* device has not written.
86+
*
87+
* This quirk is applied to all controls, regardless of their data type.
88+
* Most controls are little-endian integers, in which case the missing
89+
* bytes become 0 MSBs. For other data types, a different heuristic
90+
* could be implemented if a device is found needing it.
91+
*
92+
* We exclude UVC_GET_INFO from the quirk. UVC_GET_LEN does not need
93+
* to be excluded because its size is always 1.
94+
*/
95+
if (ret > 0 && query != UVC_GET_INFO) {
96+
memset(data + ret, 0, size - ret);
97+
dev_warn_once(&dev->udev->dev,
98+
"UVC non compliance: %s control %u on unit %u returned %d bytes when we expected %u.\n",
99+
uvc_query_name(query), cs, unit, ret, size);
100+
return 0;
101+
}
102+
82103
if (ret != -EPIPE) {
83104
dev_err(&dev->udev->dev,
84105
"Failed to query (%s) UVC control %u on unit %u: %d (exp. %u).\n",

0 commit comments

Comments
 (0)