From ccf2891070bbe89e5d6fe3f88bbc7c1f4463d3a6 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 4 Nov 2022 13:10:55 +0100 Subject: [PATCH] v4l2: fix buffer amount check When we get buffers from the driver, check if we have at least as many as we requested. If we have more, that's ok, we will simply not queue them. Previously we would ignore the input number of buffers and use the allocated amount to fill up the buffer array, which might be too small and then we crash. --- spa/plugins/v4l2/v4l2-utils.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spa/plugins/v4l2/v4l2-utils.c b/spa/plugins/v4l2/v4l2-utils.c index 9a4def62e..164ef0f4a 100644 --- a/spa/plugins/v4l2/v4l2-utils.c +++ b/spa/plugins/v4l2/v4l2-utils.c @@ -891,8 +891,9 @@ static int spa_v4l2_set_format(struct impl *this, struct spa_video_info *format, bool match; spa_zero(fmt); - spa_zero(streamparm); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + + spa_zero(streamparm); streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; switch (format->media_subtype) { @@ -1506,11 +1507,10 @@ mmap_init(struct impl *this, } spa_log_debug(this->log, "got %d buffers", reqbuf.count); - n_buffers = reqbuf.count; - if (n_buffers < 2) { - spa_log_error(this->log, "'%s' can't allocate enough buffers (%d)", - this->props.device, n_buffers); + if (reqbuf.count < n_buffers) { + spa_log_error(this->log, "'%s' can't allocate enough buffers (%d < %d)", + this->props.device, reqbuf.count, n_buffers); return -ENOMEM; }