summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-01-28 18:44:51 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-02-02 07:42:16 +0200
commit77259f7346abf0ba65057c7ecb02c96c85621e7c (patch)
treeaec5a9793dfb069b77b0334b17e1d01a49bfb9b8
parente96d02015c3a2322ad0335b969d9cb6ee83e83d0 (diff)
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>
-rw-r--r--src/v4l2/v4l2_camera_proxy.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp
index f3470a6d..e114d09f 100644
--- a/src/v4l2/v4l2_camera_proxy.cpp
+++ b/src/v4l2/v4l2_camera_proxy.cpp
@@ -104,8 +104,16 @@ void *V4L2CameraProxy::mmap(V4L2CameraFile *file, void *addr, size_t length,
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;
return MAP_FAILED;
}