summaryrefslogtreecommitdiff
path: root/src/android/mm
diff options
context:
space:
mode:
authorHirokazu Honda <hiroh@chromium.org>2021-04-04 01:22:47 +0900
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-04-04 01:18:49 +0300
commit7d7879833812635f3d34a8b41b93202b4faf4f9c (patch)
treea7462e8f610d95b4d44339b62eca5a59273977ff /src/android/mm
parentcbb580d5afbe4bc5d4a0012fa977d89e8edb547d (diff)
android: mm: cros: Handle buffer registration failure
cros::CameraBufferManager::Register() fails if a buffer handle is invalid. We should mark CameraBuffer as invalid on the failure of Register(). While the cros::CameraBufferManager Unlock() and Deregister() functions should be able to handle buffers that haven't been locked and registered, this isn't an API guarantee, and errors will be logged. Avoid this by skipping unlocking and unregistration of buffers that haven't been locked or registered. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/android/mm')
-rw-r--r--src/android/mm/cros_camera_buffer.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/android/mm/cros_camera_buffer.cpp b/src/android/mm/cros_camera_buffer.cpp
index 7df4f47c..2a82d4b7 100644
--- a/src/android/mm/cros_camera_buffer.cpp
+++ b/src/android/mm/cros_camera_buffer.cpp
@@ -37,6 +37,7 @@ private:
buffer_handle_t handle_;
unsigned int numPlanes_;
bool valid_;
+ bool registered_;
union {
void *addr;
android_ycbcr ycbcr;
@@ -49,16 +50,21 @@ private:
CameraBuffer::Private::Private(CameraBuffer *cameraBuffer,
buffer_handle_t camera3Buffer, int flags)
: Extensible::Private(cameraBuffer), handle_(camera3Buffer),
- numPlanes_(0), valid_(false)
+ numPlanes_(0), valid_(false), registered(false)
{
bufferManager_ = cros::CameraBufferManager::GetInstance();
- bufferManager_->Register(camera3Buffer);
+ int ret = bufferManager_->Register(camera3Buffer);
+ if (ret) {
+ LOG(HAL, Error) << "Failed registering a buffer: " << ret;
+ return;
+ }
+ registered_ = true;
numPlanes_ = bufferManager_->GetNumPlanes(camera3Buffer);
switch (numPlanes_) {
case 1: {
- int ret = bufferManager_->Lock(handle_, 0, 0, 0, 0, 0, &mem.addr);
+ ret = bufferManager_->Lock(handle_, 0, 0, 0, 0, 0, &mem.addr);
if (ret) {
LOG(HAL, Error) << "Single plane buffer mapping failed";
return;
@@ -67,8 +73,8 @@ CameraBuffer::Private::Private(CameraBuffer *cameraBuffer,
}
case 2:
case 3: {
- int ret = bufferManager_->LockYCbCr(handle_, 0, 0, 0, 0, 0,
- &mem.ycbcr);
+ ret = bufferManager_->LockYCbCr(handle_, 0, 0, 0, 0, 0,
+ &mem.ycbcr);
if (ret) {
LOG(HAL, Error) << "YCbCr buffer mapping failed";
return;
@@ -85,8 +91,10 @@ CameraBuffer::Private::Private(CameraBuffer *cameraBuffer,
CameraBuffer::Private::~Private()
{
- bufferManager_->Unlock(handle_);
- bufferManager_->Deregister(handle_);
+ if (valid_)
+ bufferManager_->Unlock(handle_);
+ if (registered_)
+ bufferManager_->Deregister(handle_);
}
unsigned int CameraBuffer::Private::numPlanes() const