media: videobuf2: improve max_num_buffers sanity checks
authorHans Verkuil <hverkuil-cisco@xs4all.nl>
Mon, 18 Mar 2024 14:29:33 +0000 (15:29 +0100)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Wed, 24 Apr 2024 11:49:55 +0000 (13:49 +0200)
commit1df7b8cd3a83778a36315682cd41ea21d9d81d9c
tree5adbb75f81e0edb2c32b50e6fbd70381dc5f8c5d
parente85bfd15c84e157338895a42676d07e73fe7c0e1
media: videobuf2: improve max_num_buffers sanity checks

Ensure that drivers set max_num_buffers to a value >= 32.
For now there is no reason for drivers to request a lower
limit and doing so might potentially cause userspace issues.
Note that the old check of > MAX_BUFFER_INDEX was pointless
since q->max_num_buffers was already limited to MAX_BUFFER_INDEX
or less.

Also add a sanity check in __vb2_init_fileio(), returning
-ENOSPC if a driver returns more than 32 buffers from
VIDIOC_REQBUFS with count = q->min_reqbufs_allocation.

The vb2_fileio_data struct only supports up to 32 buffers,
so we need a check there.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
drivers/media/common/videobuf2/videobuf2-core.c