* [PATCH v2] media: uvcvideo: read bulk URBs after maxPayloadSize
@ 2020-04-20 2:41 Julian Meyer
2020-04-22 4:50 ` kbuild test robot
2020-04-22 6:16 ` kbuild test robot
0 siblings, 2 replies; 5+ messages in thread
From: Julian Meyer @ 2020-04-20 2:41 UTC (permalink / raw)
Cc: Julian Meyer, Laurent Pinchart, Mauro Carvalho Chehab,
linux-media, linux-kernel
This fixes a bug that caused certain Realtek cameras to crash.
The camera would send additional UVC payloads after the maxPayloadSize
was reached. This patch modifies uvc_video_decode_bulk such that it
continues reading payloads when it reaches the maxPayloadSize if there
is more data left.
Signed-off-by: Julian Meyer <julianmeyer2000@gmail.com>
---
drivers/media/usb/uvc/uvc_video.c | 85 +++++++++++++++++++++++--------
1 file changed, 63 insertions(+), 22 deletions(-)
diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index 8fa77a81dd7f..9e07cc516796 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -1374,31 +1374,24 @@ static void uvc_video_decode_isoc(struct uvc_urb *uvc_urb,
}
}
-static void uvc_video_decode_bulk(struct uvc_urb *uvc_urb,
- struct uvc_buffer *buf, struct uvc_buffer *meta_buf)
+static int uvc_video_decode_bulk_single(struct uvc_streaming *stream,
+ struct uvc_buffer *buf, struct uvc_buffer *meta_buf,
+ struct uvc_urb *uvc_urb, u8 **mem, int *len)
{
- struct urb *urb = uvc_urb->urb;
- struct uvc_streaming *stream = uvc_urb->stream;
- u8 *mem;
- int len, ret;
+ unsigned int bytes_left;
+ int ret;
- /*
- * Ignore ZLPs if they're not part of a frame, otherwise process them
- * to trigger the end of payload detection.
- */
- if (urb->actual_length == 0 && stream->bulk.header_size == 0)
- return;
+ int length_removed = 0;
- mem = urb->transfer_buffer;
- len = urb->actual_length;
- stream->bulk.payload_size += len;
+ struct urb *urb = uvc_urb->urb;
+ unsigned int max_size = stream->bulk.max_payload_size;
/* If the URB is the first of its payload, decode and save the
* header.
*/
if (stream->bulk.header_size == 0 && !stream->bulk.skip_payload) {
do {
- ret = uvc_video_decode_start(stream, buf, mem, len);
+ ret = uvc_video_decode_start(stream, buf, *mem, *len);
if (ret == -EAGAIN)
uvc_video_next_buffers(stream, &buf, &meta_buf);
} while (ret == -EAGAIN);
@@ -1407,13 +1400,15 @@ static void uvc_video_decode_bulk(struct uvc_urb *uvc_urb,
if (ret < 0 || buf == NULL) {
stream->bulk.skip_payload = 1;
} else {
- memcpy(stream->bulk.header, mem, ret);
+ memcpy(stream->bulk.header, *mem, ret);
stream->bulk.header_size = ret;
- uvc_video_decode_meta(stream, meta_buf, mem, ret);
+ uvc_video_decode_meta(stream, meta_buf, *mem, ret);
- mem += ret;
- len -= ret;
+ *mem += ret;
+ length_removed += ret;
+ *len -= ret;
+ stream->bulk.payload_size += ret;
}
}
@@ -1423,8 +1418,22 @@ static void uvc_video_decode_bulk(struct uvc_urb *uvc_urb,
*/
/* Prepare video data for processing. */
- if (!stream->bulk.skip_payload && buf != NULL)
- uvc_video_decode_data(uvc_urb, buf, mem, len);
+ if (!stream->bulk.skip_payload && buf != NULL) {
+ bytes_left = min((unsigned int) *len,
+ max_size - stream->bulk.payload_size);
+
+ stream->bulk.payload_size += bytes_left;
+
+ uvc_video_decode_data(uvc_urb, buf, *mem, bytes_left);
+
+ *len -= bytes_left;
+ *mem += bytes_left;
+ length_removed = bytes_left;
+ } else {
+ stream->bulk.payload_size += *len;
+ length_removed = *len;
+ *len = 0;
+ }
/* Detect the payload end by a URB smaller than the maximum size (or
* a payload size equal to the maximum) and process the header again.
@@ -1442,6 +1451,38 @@ static void uvc_video_decode_bulk(struct uvc_urb *uvc_urb,
stream->bulk.skip_payload = 0;
stream->bulk.payload_size = 0;
}
+
+ return length_removed;
+}
+
+static void uvc_video_decode_bulk(struct uvc_urb *uvc_urb,
+ struct uvc_buffer *buf, struct uvc_buffer *meta_buf)
+{
+ struct urb *urb = uvc_urb->urb;
+ struct uvc_streaming *stream = uvc_urb->stream;
+ u8 *mem;
+ int len;
+ int len_processed;
+
+ /*
+ * Ignore ZLPs if they're not part of a frame, otherwise process them
+ * to trigger the end of payload detection.
+ */
+ if (urb->actual_length == 0 && stream->bulk.header_size == 0)
+ return;
+
+ mem = urb->transfer_buffer;
+ len = urb->actual_length;
+
+ while (len > 0) {
+ len_processed = uvc_video_decode_bulk_single(stream, buf,
+ meta_buf, uvc_urb, &mem, &len);
+
+ // if we don't process anything, we break out of the decode loop
+ if (len_processed == 0) {
+ return
+ }
+ }
}
static void uvc_video_encode_bulk(struct uvc_urb *uvc_urb,
--
2.26.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] media: uvcvideo: read bulk URBs after maxPayloadSize
2020-04-20 2:41 [PATCH v2] media: uvcvideo: read bulk URBs after maxPayloadSize Julian Meyer
@ 2020-04-22 4:50 ` kbuild test robot
2020-04-22 6:16 ` kbuild test robot
1 sibling, 0 replies; 5+ messages in thread
From: kbuild test robot @ 2020-04-22 4:50 UTC (permalink / raw)
To: Julian Meyer, Laurent Pinchart, Mauro Carvalho Chehab,
linux-media, linux-kernel
Cc: kbuild-all, clang-built-linux, linux-media, Julian Meyer,
Laurent Pinchart, Mauro Carvalho Chehab
[-- Attachment #1: Type: text/plain, Size: 2525 bytes --]
Hi Julian,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on v5.7-rc2 next-20200421]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Julian-Meyer/media-uvcvideo-read-bulk-URBs-after-maxPayloadSize/20200421-225554
base: git://linuxtv.org/media_tree.git master
config: arm64-defconfig (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project a9b137f9ffba8cb25dfd7dd1fb613e8aac121b37)
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
>> drivers/media/usb/uvc/uvc_video.c:1484:3: error: expected expression
}
^
1 error generated.
vim +1484 drivers/media/usb/uvc/uvc_video.c
1457
1458 static void uvc_video_decode_bulk(struct uvc_urb *uvc_urb,
1459 struct uvc_buffer *buf, struct uvc_buffer *meta_buf)
1460 {
1461 struct urb *urb = uvc_urb->urb;
1462 struct uvc_streaming *stream = uvc_urb->stream;
1463 u8 *mem;
1464 int len;
1465 int len_processed;
1466
1467 /*
1468 * Ignore ZLPs if they're not part of a frame, otherwise process them
1469 * to trigger the end of payload detection.
1470 */
1471 if (urb->actual_length == 0 && stream->bulk.header_size == 0)
1472 return;
1473
1474 mem = urb->transfer_buffer;
1475 len = urb->actual_length;
1476
1477 while (len > 0) {
1478 len_processed = uvc_video_decode_bulk_single(stream, buf,
1479 meta_buf, uvc_urb, &mem, &len);
1480
1481 // if we don't process anything, we break out of the decode loop
1482 if (len_processed == 0) {
1483 return
> 1484 }
1485 }
1486 }
1487
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 49087 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] media: uvcvideo: read bulk URBs after maxPayloadSize
@ 2020-04-22 4:50 ` kbuild test robot
0 siblings, 0 replies; 5+ messages in thread
From: kbuild test robot @ 2020-04-22 4:50 UTC (permalink / raw)
To: kbuild-all
[-- Attachment #1: Type: text/plain, Size: 2596 bytes --]
Hi Julian,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on v5.7-rc2 next-20200421]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Julian-Meyer/media-uvcvideo-read-bulk-URBs-after-maxPayloadSize/20200421-225554
base: git://linuxtv.org/media_tree.git master
config: arm64-defconfig (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project a9b137f9ffba8cb25dfd7dd1fb613e8aac121b37)
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
>> drivers/media/usb/uvc/uvc_video.c:1484:3: error: expected expression
}
^
1 error generated.
vim +1484 drivers/media/usb/uvc/uvc_video.c
1457
1458 static void uvc_video_decode_bulk(struct uvc_urb *uvc_urb,
1459 struct uvc_buffer *buf, struct uvc_buffer *meta_buf)
1460 {
1461 struct urb *urb = uvc_urb->urb;
1462 struct uvc_streaming *stream = uvc_urb->stream;
1463 u8 *mem;
1464 int len;
1465 int len_processed;
1466
1467 /*
1468 * Ignore ZLPs if they're not part of a frame, otherwise process them
1469 * to trigger the end of payload detection.
1470 */
1471 if (urb->actual_length == 0 && stream->bulk.header_size == 0)
1472 return;
1473
1474 mem = urb->transfer_buffer;
1475 len = urb->actual_length;
1476
1477 while (len > 0) {
1478 len_processed = uvc_video_decode_bulk_single(stream, buf,
1479 meta_buf, uvc_urb, &mem, &len);
1480
1481 // if we don't process anything, we break out of the decode loop
1482 if (len_processed == 0) {
1483 return
> 1484 }
1485 }
1486 }
1487
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 49087 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] media: uvcvideo: read bulk URBs after maxPayloadSize
2020-04-20 2:41 [PATCH v2] media: uvcvideo: read bulk URBs after maxPayloadSize Julian Meyer
@ 2020-04-22 6:16 ` kbuild test robot
2020-04-22 6:16 ` kbuild test robot
1 sibling, 0 replies; 5+ messages in thread
From: kbuild test robot @ 2020-04-22 6:16 UTC (permalink / raw)
To: Julian Meyer, Laurent Pinchart, Mauro Carvalho Chehab,
linux-media, linux-kernel
Cc: kbuild-all, linux-media, Julian Meyer, Laurent Pinchart,
Mauro Carvalho Chehab
[-- Attachment #1: Type: text/plain, Size: 2722 bytes --]
Hi Julian,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on v5.7-rc2 next-20200421]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Julian-Meyer/media-uvcvideo-read-bulk-URBs-after-maxPayloadSize/20200421-225554
base: git://linuxtv.org/media_tree.git master
config: arm-davinci_all_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=arm
If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <lkp@intel.com>
All error/warnings (new ones prefixed by >>):
drivers/media/usb/uvc/uvc_video.c: In function 'uvc_video_decode_bulk':
>> drivers/media/usb/uvc/uvc_video.c:1484:3: error: expected expression before '}' token
1484 | }
| ^
>> drivers/media/usb/uvc/uvc_video.c:1484:3: warning: 'return' with a value, in function returning void [-Wreturn-type]
drivers/media/usb/uvc/uvc_video.c:1458:13: note: declared here
1458 | static void uvc_video_decode_bulk(struct uvc_urb *uvc_urb,
| ^~~~~~~~~~~~~~~~~~~~~
vim +1484 drivers/media/usb/uvc/uvc_video.c
1457
1458 static void uvc_video_decode_bulk(struct uvc_urb *uvc_urb,
1459 struct uvc_buffer *buf, struct uvc_buffer *meta_buf)
1460 {
1461 struct urb *urb = uvc_urb->urb;
1462 struct uvc_streaming *stream = uvc_urb->stream;
1463 u8 *mem;
1464 int len;
1465 int len_processed;
1466
1467 /*
1468 * Ignore ZLPs if they're not part of a frame, otherwise process them
1469 * to trigger the end of payload detection.
1470 */
1471 if (urb->actual_length == 0 && stream->bulk.header_size == 0)
1472 return;
1473
1474 mem = urb->transfer_buffer;
1475 len = urb->actual_length;
1476
1477 while (len > 0) {
1478 len_processed = uvc_video_decode_bulk_single(stream, buf,
1479 meta_buf, uvc_urb, &mem, &len);
1480
1481 // if we don't process anything, we break out of the decode loop
1482 if (len_processed == 0) {
1483 return
> 1484 }
1485 }
1486 }
1487
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 31566 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] media: uvcvideo: read bulk URBs after maxPayloadSize
@ 2020-04-22 6:16 ` kbuild test robot
0 siblings, 0 replies; 5+ messages in thread
From: kbuild test robot @ 2020-04-22 6:16 UTC (permalink / raw)
To: kbuild-all
[-- Attachment #1: Type: text/plain, Size: 2795 bytes --]
Hi Julian,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on v5.7-rc2 next-20200421]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Julian-Meyer/media-uvcvideo-read-bulk-URBs-after-maxPayloadSize/20200421-225554
base: git://linuxtv.org/media_tree.git master
config: arm-davinci_all_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=arm
If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <lkp@intel.com>
All error/warnings (new ones prefixed by >>):
drivers/media/usb/uvc/uvc_video.c: In function 'uvc_video_decode_bulk':
>> drivers/media/usb/uvc/uvc_video.c:1484:3: error: expected expression before '}' token
1484 | }
| ^
>> drivers/media/usb/uvc/uvc_video.c:1484:3: warning: 'return' with a value, in function returning void [-Wreturn-type]
drivers/media/usb/uvc/uvc_video.c:1458:13: note: declared here
1458 | static void uvc_video_decode_bulk(struct uvc_urb *uvc_urb,
| ^~~~~~~~~~~~~~~~~~~~~
vim +1484 drivers/media/usb/uvc/uvc_video.c
1457
1458 static void uvc_video_decode_bulk(struct uvc_urb *uvc_urb,
1459 struct uvc_buffer *buf, struct uvc_buffer *meta_buf)
1460 {
1461 struct urb *urb = uvc_urb->urb;
1462 struct uvc_streaming *stream = uvc_urb->stream;
1463 u8 *mem;
1464 int len;
1465 int len_processed;
1466
1467 /*
1468 * Ignore ZLPs if they're not part of a frame, otherwise process them
1469 * to trigger the end of payload detection.
1470 */
1471 if (urb->actual_length == 0 && stream->bulk.header_size == 0)
1472 return;
1473
1474 mem = urb->transfer_buffer;
1475 len = urb->actual_length;
1476
1477 while (len > 0) {
1478 len_processed = uvc_video_decode_bulk_single(stream, buf,
1479 meta_buf, uvc_urb, &mem, &len);
1480
1481 // if we don't process anything, we break out of the decode loop
1482 if (len_processed == 0) {
1483 return
> 1484 }
1485 }
1486 }
1487
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 31566 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-04-22 6:17 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-20 2:41 [PATCH v2] media: uvcvideo: read bulk URBs after maxPayloadSize Julian Meyer
2020-04-22 4:50 ` kbuild test robot
2020-04-22 4:50 ` kbuild test robot
2020-04-22 6:16 ` kbuild test robot
2020-04-22 6:16 ` kbuild test robot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.