[libcamera-devel,v5,10/12] android: camera_device: Fix variables access without protection
diff mbox series

Message ID 20211201075348.3121186-11-hiroh@chromium.org
State Accepted
Headers show
Series
  • Introduce clang thread safety annotations
Related show

Commit Message

Hirokazu Honda Dec. 1, 2021, 7:53 a.m. UTC
This fixes the code accessing descriptors and
Camera3RequestDescriptor::pendingStreamsToProcess_ without holding
descriptorsMutex_ and Camera3RequestDescriptor::streamProcessMutex_
in CameraDevice.

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/android/camera_device.cpp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Umang Jain Dec. 1, 2021, 10:35 a.m. UTC | #1
Hi Hiro,

On 12/1/21 1:23 PM, Hirokazu Honda wrote:
> This fixes the code accessing descriptors and
> Camera3RequestDescriptor::pendingStreamsToProcess_ without holding
> descriptorsMutex_ and Camera3RequestDescriptor::streamProcessMutex_
> in CameraDevice.
>
> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>


Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>

> ---
>   src/android/camera_device.cpp | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index d74307a2..c7de5da0 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -421,7 +421,11 @@ void CameraDevice::stop()
>   	worker_.stop();
>   	camera_->stop();
>   
> -	descriptors_ = {};
> +	{
> +		MutexLocker descriptorsLock(descriptorsMutex_);
> +		descriptors_ = {};
> +	}
> +
>   	streams_.clear();
>   
>   	state_ = State::Stopped;
> @@ -918,6 +922,9 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques
>   		 */
>   		FrameBuffer *frameBuffer = nullptr;
>   		int acquireFence = -1;
> +
> +		MutexLocker lock(descriptor->streamsProcessMutex_);
> +
>   		switch (cameraStream->type()) {
>   		case CameraStream::Type::Mapped:
>   			/*

Patch
diff mbox series

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index d74307a2..c7de5da0 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -421,7 +421,11 @@  void CameraDevice::stop()
 	worker_.stop();
 	camera_->stop();
 
-	descriptors_ = {};
+	{
+		MutexLocker descriptorsLock(descriptorsMutex_);
+		descriptors_ = {};
+	}
+
 	streams_.clear();
 
 	state_ = State::Stopped;
@@ -918,6 +922,9 @@  int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques
 		 */
 		FrameBuffer *frameBuffer = nullptr;
 		int acquireFence = -1;
+
+		MutexLocker lock(descriptor->streamsProcessMutex_);
+
 		switch (cameraStream->type()) {
 		case CameraStream::Type::Mapped:
 			/*