v4l2: Accept read-only buffers mappings and require MAP_SHARED

V4L2 is happy to map buffers read-only for capture devices (but rejects
write-only mappings). We can support this as the dmabuf mmap()
implementation supports it. This change fixes usage of the V4L2
compatibility layer with OpenCV.

While at it, attempt to validate the other flags. videobuf2 requires
MAP_SHARED and doesn't check other flags, so mimic the same behaviour.
While unlikly, other flags could get rejected by other kernel layers for
V4L2 buffers but not for dmabuf. This can be handled later if the need
arises.

Reported-by: Nejc Galof <galof.nejc@gmail.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Nejc Galof <galof.nejc@gmail.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
This commit is contained in:
Laurent Pinchart 2022-01-28 18:44:51 +02:00
parent e96d02015c
commit 77259f7346

View file

@ -104,8 +104,16 @@ void *V4L2CameraProxy::mmap(V4L2CameraFile *file, void *addr, size_t length,
MutexLocker locker(proxyMutex_); MutexLocker locker(proxyMutex_);
/* \todo Validate prot and flags properly. */ /*
if (prot != (PROT_READ | PROT_WRITE)) { * Mimic the videobuf2 behaviour, which requires PROT_READ and
* MAP_SHARED.
*/
if (!(prot & PROT_READ)) {
errno = EINVAL;
return MAP_FAILED;
}
if (!(flags & MAP_SHARED)) {
errno = EINVAL; errno = EINVAL;
return MAP_FAILED; return MAP_FAILED;
} }