From patchwork Fri Sep 24 06:44:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 13914 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 75A9DBDC71 for ; Fri, 24 Sep 2021 06:44:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C219B6918C; Fri, 24 Sep 2021 08:44:18 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="U2gB/TI+"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4F52960242 for ; Fri, 24 Sep 2021 08:44:17 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.251.226.86]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 34EAC45E; Fri, 24 Sep 2021 08:44:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1632465856; bh=biJrUr6DrGWrF3HLHuAduc6PaHH7FxsB+VlxpoRXGVA=; h=From:To:Cc:Subject:Date:From; b=U2gB/TI+PtiGnVvAKmUsc2qaX+iFBda/BF+HdrTnEC2g+aq46GEVn22plWLy8cL2P n1y9TF5qTCTllwoceeXddUkxO4ps+zS/Zbh+l4bGyK0d/MlQzcctaHEPy3YwkQPbCx QcrxZiT7fPgzcLBmi4Slr9IpvAPwsCybMdJ1rTWg= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Fri, 24 Sep 2021 12:14:09 +0530 Message-Id: <20210924064409.317140-1-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] android: camera_device: Fix race on queuing capture request 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" The Camera3RequestDescriptor containing the capture request is adding to the descriptors_ map after a call to CameraWorker::queueRequest(). This is a race condition since CameraWorker::queueRequest() queues request to libcamera::Camera asynchronously and the addition of the descriptor to the map occurs with std::move(). Hence, it might happen that the async queueRequest() hasn't finished but the descriptor gets std::move()ed. Fix it by adding the descriptor to map first, before CameraWorker::queueRequest(). Signed-off-by: Umang Jain --- src/android/camera_device.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 21844e51..c4c03d86 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1065,13 +1065,14 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques state_ = State::Running; } - worker_.queueRequest(descriptor.request_.get()); - + unsigned long requestCookie = descriptor.request_->cookie(); { MutexLocker descriptorsLock(descriptorsMutex_); - descriptors_[descriptor.request_->cookie()] = std::move(descriptor); + descriptors_[requestCookie] = std::move(descriptor); } + worker_.queueRequest(descriptors_[requestCookie].request_.get()); + return 0; }