From 77dd4aaad3d71a31a8b546758d8ee09e9b50d6e0 Mon Sep 17 00:00:00 2001 From: Yahan Zhou Date: Thu, 22 Jun 2017 17:04:41 -0700 Subject: [PATCH] Camera: fix recursive lock in CameraDevice 1.0 Several functions call close() while they are holding a lock, which results in recursive locking. This CL implements close_locked() to avoid such behavior. Bug: 62919192 Test: run vts -m VtsHalCameraProviderV2_4Target, and camera should still work after it Change-Id: Ib38e1de19ed3c927bfb645c0c777c04f157f2b88 --- camera/device/1.0/default/CameraDevice.cpp | 12 ++++++++---- camera/device/1.0/default/CameraDevice_1_0.h | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/camera/device/1.0/default/CameraDevice.cpp b/camera/device/1.0/default/CameraDevice.cpp index 6f4e70f834..c53c0d8b56 100644 --- a/camera/device/1.0/default/CameraDevice.cpp +++ b/camera/device/1.0/default/CameraDevice.cpp @@ -116,7 +116,7 @@ CameraDevice::~CameraDevice() { Mutex::Autolock _l(mLock); if (mDevice != nullptr) { ALOGW("%s: camera %s is deleted while open", __FUNCTION__, mCameraId.c_str()); - close(); + closeLocked(); } mHalPreviewWindow.cleanUpCirculatingBuffers(); } @@ -130,7 +130,7 @@ void CameraDevice::setConnectionStatus(bool connected) { } if (!connected) { ALOGW("%s: camera %s is disconneted. Closing", __FUNCTION__, mCameraId.c_str()); - close(); + closeLocked(); } return; } @@ -982,8 +982,13 @@ Return CameraDevice::sendCommand(CommandType cmd, int32_t arg1, int32_t } Return CameraDevice::close() { - ALOGI("Closing camera %s", mCameraId.c_str()); Mutex::Autolock _l(mLock); + closeLocked(); + return Void(); +} + +void CameraDevice::closeLocked() { + ALOGI("Closing camera %s", mCameraId.c_str()); if(mDevice) { int rc = mDevice->common.close(&mDevice->common); if (rc != OK) { @@ -991,7 +996,6 @@ Return CameraDevice::close() { } mDevice = nullptr; } - return Void(); } } // namespace implementation diff --git a/camera/device/1.0/default/CameraDevice_1_0.h b/camera/device/1.0/default/CameraDevice_1_0.h index 0e5a49b4eb..c078596317 100644 --- a/camera/device/1.0/default/CameraDevice_1_0.h +++ b/camera/device/1.0/default/CameraDevice_1_0.h @@ -222,6 +222,7 @@ private: static status_t getStatusT(const Status& s); Status initStatus() const; + void closeLocked(); }; } // namespace implementation