[libcamera-devel] [PATCH] libcamera: base: shared_fd: Don't dup() an invalid fd
Umang Jain
umang.jain at ideasonboard.com
Tue Dec 7 17:37:10 CET 2021
Hi,
On 12/6/21 7:37 PM, Laurent Pinchart wrote:
> 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 at ideasonboard.com>
> ---
> src/libcamera/base/shared_fd.cpp | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/src/libcamera/base/shared_fd.cpp b/src/libcamera/base/shared_fd.cpp
> index bd2ab5aa25b7..c711cf579a04 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 {};
> +
simple enough
Reviewed-by: Umang Jain <umang.jain at ideasonboard.com>
> UniqueFD dupFd(::dup(get()));
> if (!dupFd.isValid()) {
> int ret = -errno;
>
> base-commit: f8d2f17a3db5ac490d7b505253a98d6795c2b630
More information about the libcamera-devel
mailing list