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

Message ID 20190203105517.5355-3-kieran.bingham@ideasonboard.com
State Superseded
Headers show
Series
  • libcamera: Buffer Objects
Related show

Commit Message

Kieran Bingham Feb. 3, 2019, 10:55 a.m. UTC
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@ideasonboard.com>
---
 src/libcamera/buffer.cpp | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

Patch

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