From patchwork Mon Jan 13 17:06:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 22545 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 213E1C326C for ; Mon, 13 Jan 2025 17:07:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2541868503; Mon, 13 Jan 2025 18:07:34 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Xknt2VvZ"; dkim-atps=neutral Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1BFE2684E7 for ; Mon, 13 Jan 2025 18:07:32 +0100 (CET) Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-21634338cfdso63707495ad.2 for ; Mon, 13 Jan 2025 09:07:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1736788050; x=1737392850; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=uy20PlYmxv95KjKfx5pbj5Etq3c/K5m8G1F56/PKgKM=; b=Xknt2VvZ+qvew4hVrZ6s8YkPsJemQf/o3ljMl9L/BTeikRt78IBjkykdeFA17W6D1d oeJwVFQvsh5DG9kV0rccxLlaWYvS0ugecQZpxxC1GaSZYGINrxgD3cBh+F6FFTFtJRo5 e5erD3VjMyY2QsJJwUmU5I84wavX7HP6DEIWs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736788050; x=1737392850; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=uy20PlYmxv95KjKfx5pbj5Etq3c/K5m8G1F56/PKgKM=; b=WgSTtt+9Ua8we8+ln67W8wp4LIIOAZnzewOudSef7CblWQkZoF681ldh+U0KzR/HV2 +M6cn5i1BmO2pIw56j1Vecx+kCGUHfsF6oRwVgkqxAgs0DnjaEeKIsaMF2CF/cuWNzsE YkevJuIMP8eDwdfG+KOWw9XPhOxlpDL3QISNaCmH7cyup66AKzptNvJdhM4XtZ+c2YoI ixh3aNGWpvS6RRP/GF799vA9qlZpV+DOlkGCwTVL/8f8YdSfrNSQ36VNp1+vq8g2Vg03 +1w/EhI+OkJWZsFaiI/L9ZjnNOhD85WazBg6j89Z3A32XinLvB05jhtddvHdXOi6K+ha NK4g== X-Gm-Message-State: AOJu0YyYt+y3vXkdxmJSNoAQV2YiBztEnyLKzUr9TEStPxYhvlsoY+4T 2gBeaz+Vvcarf714mZ2o7pVB4fEPiKvm5RF3HwxaSAIBIJ8pjVKBhW2dDI3nrONlWtwmxoKslf/ RJw== X-Gm-Gg: ASbGncsXbMvimRejemKnkf/ldiyK0aKsabJCaZsDv7AUzNeEHytqFCokNFhnECXrnsg ildRVZcHD7d+QebYZLIOcsZnEibtDVmf+vwaauAHFs8+Ly3sENqFT0q7i2qLrP/cTXDGYgv8RbI +xZLyj++a/DAVUOO7iSOnlVEH2mh0/jPjyB2F1cnlDVtzRopPnCUSyoDKTJP9btLS57V0mdf4OG L/+K2PoV5ZIzOkAF/2K92R20yedqczBUg2+IwCfBZcCQ2Zxakrhf+kRhy/LEiRBaEpy+c6nHapA xlrt8sfu9diIwwrG6tYIlPGjH//sk3FqFgwYSVu/nIhTlcWHNSMAynpW1qv1R+M= X-Google-Smtp-Source: AGHT+IH0YCv8rEzCvpo1alBKK/OT587DOJdVAbkWG8PZ0FgBEvBLT5Dk71Asv2vlJKU43BerOJ7hqA== X-Received: by 2002:a05:6a00:1152:b0:725:f282:1f04 with SMTP id d2e1a72fcca58-72d21fcf2d9mr30827239b3a.18.1736788050187; Mon, 13 Jan 2025 09:07:30 -0800 (PST) Received: from chenghaoyang-low.c.googlers.com.com (21.160.199.104.bc.googleusercontent.com. [104.199.160.21]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72d4067ee81sm6256303b3a.132.2025.01.13.09.07.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 09:07:29 -0800 (PST) From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Harvey Yang Subject: [PATCH] DmaBufAllocator: Avoid syncing with an invalid file descriptor Date: Mon, 13 Jan 2025 17:06:56 +0000 Message-ID: <20250113170724.801717-1-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 Tested-by: Milan Zamazal --- 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 };