summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-12-06 14:48:16 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-12-07 19:09:22 +0200
commit72679c682eb0b9f03948f258a26f78c037d33c48 (patch)
treedab82bec75e56a349f38bca5ffd2c78dc0e5a20a /src
parent37c41aa6a69985f99f9540dc89d094df61770fdc (diff)
libcamera: base: shared_fd: Don't dup() an invalid fd
The SharedFD::dup() implementation calls the C library dup() function on the fd. When the SharedFD instance is invalid, this produces an invalid fd, which is the correct behaviour, but logs an error message. Fix it by returning an invalid UniqueFD directly when the SharedFD is invalid. This also saves a system call, which is always nice to do. Fixes: fcf98514cb4e ("libcamera: base: file_descriptor: Return UniqueFD from dup()") Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/base/shared_fd.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/libcamera/base/shared_fd.cpp b/src/libcamera/base/shared_fd.cpp
index bd2ab5aa..c711cf57 100644
--- a/src/libcamera/base/shared_fd.cpp
+++ b/src/libcamera/base/shared_fd.cpp
@@ -253,6 +253,9 @@ SharedFD &SharedFD::operator=(SharedFD &&other)
*/
UniqueFD SharedFD::dup() const
{
+ if (!isValid())
+ return {};
+
UniqueFD dupFd(::dup(get()));
if (!dupFd.isValid()) {
int ret = -errno;