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.
This commit is contained in:
Wim Taymans 2022-11-04 13:10:55 +01:00
parent ec5f2d7337
commit ccf2891070

View file

@ -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;
}