[libcamera-devel] [PATCH v2 2/5] libcamera: buffer: Fix setDmabuf operations

Kieran Bingham kieran.bingham at ideasonboard.com
Sun Feb 3 11:55:14 CET 2019


The setDmabuf validation for the input FD was incorrect.

Fix this, and update the documentation and error reporting.

Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
---
 src/libcamera/buffer.cpp | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/libcamera/buffer.cpp b/src/libcamera/buffer.cpp
index 6dfebfc6bb28..c86847daf193 100644
--- a/src/libcamera/buffer.cpp
+++ b/src/libcamera/buffer.cpp
@@ -43,6 +43,8 @@ Buffer::~Buffer()
  * \brief Set the dmabuf file handle backing the buffer
  *
  * The \a fd dmabuf file handle is duplicated and stored.
+ *
+ * \return 0 on success or a negative error value otherwise.
  */
 int Buffer::setDmabuf(int fd)
 {
@@ -51,12 +53,19 @@ int Buffer::setDmabuf(int fd)
 		fd_ = -1;
 	}
 
-	if (fd != -1)
-		return 0;
+	if (fd < 0) {
+		LOG(Buffer, Error) << "Invalid DMABuf FD provided";
+		return -EINVAL;
+	}
 
 	fd_ = dup(fd);
-	if (fd_ == -1)
-		return -errno;
+	if (fd_ == -1) {
+		int ret = -errno;
+		LOG(Buffer, Error)
+			<< "Failed to duplicate Dmabuf: " << strerror(-ret);
+
+		return ret;
+	}
 
 	return 0;
 }
-- 
2.19.1



More information about the libcamera-devel mailing list