libcamera: v4l2_videodevice: Fix potential errno overwrite

The errno variable can potentially be overwritten by operator<<(). Store
it in a local variable before logging the error message.

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>
This commit is contained in:
Laurent Pinchart 2022-03-31 18:08:22 +03:00
parent b90faccb2c
commit f9e2df9519

View file

@ -647,14 +647,17 @@ int V4L2VideoDevice::open()
*/ */
int V4L2VideoDevice::open(SharedFD handle, enum v4l2_buf_type type) int V4L2VideoDevice::open(SharedFD handle, enum v4l2_buf_type type)
{ {
int ret;
UniqueFD newFd = handle.dup(); UniqueFD newFd = handle.dup();
if (!newFd.isValid()) { if (!newFd.isValid()) {
ret = -errno;
LOG(V4L2, Error) << "Failed to duplicate file handle: " LOG(V4L2, Error) << "Failed to duplicate file handle: "
<< strerror(errno); << strerror(-ret);
return -errno; return ret;
} }
int ret = V4L2Device::setFd(std::move(newFd)); ret = V4L2Device::setFd(std::move(newFd));
if (ret < 0) { if (ret < 0) {
LOG(V4L2, Error) << "Failed to set file handle: " LOG(V4L2, Error) << "Failed to set file handle: "
<< strerror(-ret); << strerror(-ret);