[PATCH] DmaBufAllocator: Avoid syncing with an invalid file descriptor
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Mon Jan 13 19:00:41 CET 2025
On Mon, Jan 13, 2025 at 05:06:56PM +0000, Harvey Yang wrote:
> As DmaSyncer disables the copy c'tor, the move c'tor will be used
> instead. This leaves some DmaSyncers with invalid SharedFDs. They should
> avoid syncing with invalid file descriptors in the d'tor.
>
> Fixes: 545046a41e17 ("DmaBufAllocator: Make DmaSyncer non-copyable")
> Signed-off-by: Harvey Yang <chenghaoyang at chromium.org>
> ---
> src/libcamera/dma_buf_allocator.cpp | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/src/libcamera/dma_buf_allocator.cpp b/src/libcamera/dma_buf_allocator.cpp
> index a014c3b4263c..17a888efaa40 100644
> --- a/src/libcamera/dma_buf_allocator.cpp
> +++ b/src/libcamera/dma_buf_allocator.cpp
> @@ -330,6 +330,11 @@ DmaSyncer::~DmaSyncer()
>
> void DmaSyncer::sync(uint64_t step)
> {
> + // DmaSyncer might be moved and left an empty SharedFD.
> + // Avoid syncing with an invalid file descriptor in this case.
Comment style.
> + if (!fd_.isValid())
> + return;
I would move this to the destructor, as calling sync() with an invalid
fd in the constructor is an error that should result in a loud log
message.
> +
> struct dma_buf_sync sync = {
> .flags = flags_ | step
> };
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list