diff options
author | Hirokazu Honda <hiroh@chromium.org> | 2021-06-10 16:50:23 +0900 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2021-12-04 23:05:04 +0200 |
commit | cfe4f9622ead96702d879835ca9dd2942d503399 (patch) | |
tree | c2d52be45b44f5fcd67e297a0da4fdd3ece44bed /src/libcamera/v4l2_videodevice.cpp | |
parent | 91dcd719d7c4aba3cd9942a77d03068c3f05c0a5 (diff) |
libcamera: v4l2_device: Use UniqueFD for a file descriptor
Manages a file descriptor owned by V4L2Device for a v4l2 device node
by UniqueFD.
Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src/libcamera/v4l2_videodevice.cpp')
-rw-r--r-- | src/libcamera/v4l2_videodevice.cpp | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 0a85bcf6..c95626d3 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -24,6 +24,7 @@ #include <libcamera/base/event_notifier.h> #include <libcamera/base/file_descriptor.h> #include <libcamera/base/log.h> +#include <libcamera/base/unique_fd.h> #include <libcamera/base/utils.h> #include "libcamera/internal/formats.h" @@ -620,22 +621,17 @@ int V4L2VideoDevice::open() */ int V4L2VideoDevice::open(int handle, enum v4l2_buf_type type) { - int ret; - int newFd; - - newFd = dup(handle); - if (newFd < 0) { - ret = -errno; + UniqueFD newFd(dup(handle)); + if (!newFd.isValid()) { LOG(V4L2, Error) << "Failed to duplicate file handle: " - << strerror(-ret); - return ret; + << strerror(errno); + return -errno; } - ret = V4L2Device::setFd(newFd); + int ret = V4L2Device::setFd(std::move(newFd)); if (ret < 0) { LOG(V4L2, Error) << "Failed to set file handle: " << strerror(-ret); - ::close(newFd); return ret; } |