From patchwork Mon Jan 13 20:28:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 22546 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 808D5C326C for ; Mon, 13 Jan 2025 20:28:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3B1AB68541; Mon, 13 Jan 2025 21:28:53 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="bRB2Tp8f"; dkim-atps=neutral Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B048B684E7 for ; Mon, 13 Jan 2025 21:28:51 +0100 (CET) Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-2efe25558ddso5967917a91.2 for ; Mon, 13 Jan 2025 12:28:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1736800130; x=1737404930; 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=O7QZRjL37SiHN0EP1f1IRNNfKjFjt5+Xrwt6hRmT81Y=; b=bRB2Tp8fXllepo11z58eFSccXpi0QfNVv/6o0Db0er0LOv3xFiwQqvG0dCcRryM0xb uXkidmA5gm/EIvVPQKE1IGhbBZN/YVmG72DAz3qbhkp3imttuPBK3c71u2QvGu84GGDj wnfhspD7VPaDBpeXS8X84drkoh/VOPgW/tRvU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736800130; x=1737404930; 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=O7QZRjL37SiHN0EP1f1IRNNfKjFjt5+Xrwt6hRmT81Y=; b=i7O3Pmi9kaLPuX0WdJDT71PlGF07y629S8P97GaJwK2EpLm3FBc8jB1rZNz+SmKZJl IdUlCyzo0nyxyVvbYTlXbV/a8mbPh6TVAwfbXf1jFkv2E4Rda0S2d8bW0Zm/AJpR9w7r AiBZymtdh4+aRYJy60cuf583fSnmfNEN3nh2oSfcmFGRwiY3sjjlWVuysvT1y+J24tBu Wg9CyPHjOlokvapZR5+KPT7KI1MQg8DzKRLOYv17Q/ZT2ib921bdhizgNuArVtEG/BZz 51REK6onQf+QKqHc3oz1xJKoudHCCIskhCcz+ftlkfRUgBCLFmqdlsfUI6HEyiNdiWVm 0vIA== X-Gm-Message-State: AOJu0Yx4H9v34FwGSedELNnCgsShCkWYZ0pIHNie7s3y/VzhiAHz0Wll uJEJu32TKhvqpo9VUIVgHFs+0twey5x+zMhsPJrbyfa5jkDcEhkvQGKReMaLWAgQ0pcEKEDaQEv ++A== X-Gm-Gg: ASbGncv7HlKX8GJbpkLQr/IBkhWRqbOhkdBCSyrkqGM+GCujlAblxbT0fKKODZBwfHA Os4Q29HDTBmHDVe/Al0bLbkrQAO2hCw+hfAkzVq7OsaMx4GEzzpsvnkZlwIOTIgnCQYHU+OakZM oJqaPY8gGuYcQskhVNcWhDb+6x9xPg0IHo4KfNWb+9Yjr8sc6hiXyFA2/fFkD36jNhoYT+qlzzN n5cqSFg1U3A+MMpSEW1o5785xdHd/douaHAIAN2gj8wdceS4M92uTjs20dK/qYQ8TOAhEMfc0Ui PXE9GJulEfOI07SbdRDFc0/7n29ooYOlpXyWV70cfuwLmMPfKNRBOEP1LrZgyJ0= X-Google-Smtp-Source: AGHT+IFc43cCY6vUvfmjhfciTS6Sgu7pOpnDGzAAket7KOnbJ/HPScAzks2xFEux70fERea2u5sa+A== X-Received: by 2002:a17:90b:258b:b0:2ee:ab04:1037 with SMTP id 98e67ed59e1d1-2f548ec788amr36264578a91.17.1736800129879; Mon, 13 Jan 2025 12:28:49 -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 98e67ed59e1d1-2f5593d0911sm9074143a91.8.2025.01.13.12.28.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 12:28:49 -0800 (PST) From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Harvey Yang , Milan Zamazal Subject: [PATCH v2] DmaBufAllocator: Avoid syncing with an invalid file descriptor Date: Mon, 13 Jan 2025 20:28:38 +0000 Message-ID: <20250113202843.843466-1-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.47.1.688.g23fc6f90ad-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 Reviewed-by: Milan Zamazal Reviewed-by: Kieran Bingham --- src/libcamera/dma_buf_allocator.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libcamera/dma_buf_allocator.cpp b/src/libcamera/dma_buf_allocator.cpp index a014c3b4263c..d8c62dd67a96 100644 --- a/src/libcamera/dma_buf_allocator.cpp +++ b/src/libcamera/dma_buf_allocator.cpp @@ -325,7 +325,12 @@ DmaSyncer::DmaSyncer(SharedFD fd, SyncType type) DmaSyncer::~DmaSyncer() { - sync(DMA_BUF_SYNC_END); + /* + * DmaSyncer might be moved and left with an empty SharedFD. + * Avoid syncing with an invalid file descriptor in this case. + */ + if (fd_.isValid()) + sync(DMA_BUF_SYNC_END); } void DmaSyncer::sync(uint64_t step)