[libcamera-devel,3/3] libcamera: v4l2_videodevice: Use FileDescriptor "fd move" constructor

Message ID 20200518164804.10088-3-laurent.pinchart@ideasonboard.com
State Accepted
Commit dfa25e18334c9dc68b1939c62d6b711ece153f92
Headers show
Series
  • [libcamera-devel,1/3] libcamera: file_descriptor: Implement move semantics for constructor
Related show

Commit Message

Laurent Pinchart May 18, 2020, 4:48 p.m. UTC
Use the newly added "fd move" constructor of the FileDescriptor class to
avoid dup() + close().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/libcamera/v4l2_videodevice.cpp | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

Comments

Niklas Söderlund May 19, 2020, 1:44 p.m. UTC | #1
Hi Laurent,

Thanks for your work.

On 2020-05-18 19:48:04 +0300, Laurent Pinchart wrote:
> Use the newly added "fd move" constructor of the FileDescriptor class to
> avoid dup() + close().
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

> ---
>  src/libcamera/v4l2_videodevice.cpp | 9 +--------
>  1 file changed, 1 insertion(+), 8 deletions(-)
> 
> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> index fbe55bc6f54f..3614b2ed1cbc 100644
> --- a/src/libcamera/v4l2_videodevice.cpp
> +++ b/src/libcamera/v4l2_videodevice.cpp
> @@ -1276,14 +1276,7 @@ FileDescriptor V4L2VideoDevice::exportDmabufFd(unsigned int index,
>  		return FileDescriptor();
>  	}
>  
> -	FileDescriptor fd(expbuf.fd);
> -	/*
> -	 * FileDescriptor takes a duplicate of fd, so we must close the
> -	 * original here, otherwise it will be left dangling.
> -	 */
> -	::close(expbuf.fd);
> -
> -	return fd;
> +	return FileDescriptor(std::move(expbuf.fd));
>  }
>  
>  /**
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
Naushir Patuck May 19, 2020, 2:41 p.m. UTC | #2
Hi Laurent,

On Mon, 18 May 2020 at 17:48, Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> Use the newly added "fd move" constructor of the FileDescriptor class to
> avoid dup() + close().
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Naushir Patuck <naush@raspberrypi.com>

> ---
>  src/libcamera/v4l2_videodevice.cpp | 9 +--------
>  1 file changed, 1 insertion(+), 8 deletions(-)
>
> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> index fbe55bc6f54f..3614b2ed1cbc 100644
> --- a/src/libcamera/v4l2_videodevice.cpp
> +++ b/src/libcamera/v4l2_videodevice.cpp
> @@ -1276,14 +1276,7 @@ FileDescriptor V4L2VideoDevice::exportDmabufFd(unsigned int index,
>                 return FileDescriptor();
>         }
>
> -       FileDescriptor fd(expbuf.fd);
> -       /*
> -        * FileDescriptor takes a duplicate of fd, so we must close the
> -        * original here, otherwise it will be left dangling.
> -        */
> -       ::close(expbuf.fd);
> -
> -       return fd;
> +       return FileDescriptor(std::move(expbuf.fd));
>  }
>
>  /**
> --
> Regards,
>
> Laurent Pinchart
>

Patch

diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index fbe55bc6f54f..3614b2ed1cbc 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -1276,14 +1276,7 @@  FileDescriptor V4L2VideoDevice::exportDmabufFd(unsigned int index,
 		return FileDescriptor();
 	}
 
-	FileDescriptor fd(expbuf.fd);
-	/*
-	 * FileDescriptor takes a duplicate of fd, so we must close the
-	 * original here, otherwise it will be left dangling.
-	 */
-	::close(expbuf.fd);
-
-	return fd;
+	return FileDescriptor(std::move(expbuf.fd));
 }
 
 /**