[PATCH] DmaBufAllocator: Avoid syncing with an invalid file descriptor

Harvey Yang chenghaoyang at chromium.org
Mon Jan 13 18:06:56 CET 2025


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.
+	if (!fd_.isValid())
+		return;
+
 	struct dma_buf_sync sync = {
 		.flags = flags_ | step
 	};
-- 
2.47.1.613.gc27f4b7a9f-goog



More information about the libcamera-devel mailing list