From patchwork Sat Apr 3 16:22:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11833 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 AAA9EBD695 for ; Sat, 3 Apr 2021 16:22:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 21D4C602E6; Sat, 3 Apr 2021 18:22:57 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="EOjlb9nu"; dkim-atps=neutral Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9DB06602CF for ; Sat, 3 Apr 2021 18:22:55 +0200 (CEST) Received: by mail-pj1-x1032.google.com with SMTP id q6-20020a17090a4306b02900c42a012202so3870590pjg.5 for ; Sat, 03 Apr 2021 09:22:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/7WPKnF1v7rmDLs+9qwxFiqmjTPt3Tvt18IHTeZdQyM=; b=EOjlb9nuy3NACuIHPCnByW+upx8Kf12yac6lu6UT4hgzljqCpgMYeANgDV6cCac3N3 yTf3riSHMRaUM8l/4IeMbI6Rbvyci4Qt8+auEF+q0Z5xy9vy1s6PK6QSXH/XoOWg+HUX XDRJvMbczV5uMVVVHfyIXI/h4gV/6seVzVd6M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/7WPKnF1v7rmDLs+9qwxFiqmjTPt3Tvt18IHTeZdQyM=; b=kpRYwzQkZQmX+4MHFPSFjuNhAdAB1OKQ6vQmwNlokh9q3uzQQf0JvZ28yJNSeg6Olb pGUOR/MTiSM7JmBTPhBUOwCghtzD8/HuFVxGbvZcUhx4RaaSk2jpgykz06kwNKk39ai9 N58ssrCv4XVdbcjTuMiElkrffGKJRkqT5aufB3Ks/QloGZ+nifvD1VEFQzZ/40S/mA9c Ci+MYJCC/u7ETi4xW0D2m1ZFWBNPMv7nDSNAPMPGNSaolDRE8iVTnPUXjZ80NXd1En7R 4ykTZCfCCUGI+mXOOaSDj2qd6WwKNgSrvtyxJDB8JGev/eGNx1pdAxvIW1I6EifeN8uA S40g== X-Gm-Message-State: AOAM531+4CPG+ePivh8Dd7yMg6K8JV/LJ1bPMM5I2ioPQNZ79fhQqTGs +/S1OWGnjMGBl9kS/oAX/r9SFeESzdaSVw== X-Google-Smtp-Source: ABdhPJz44ZUK7n0CkgADnl6KzV0hzRPMQJglNBsGvazNOWmlcUTS3WJjPyUH8Z5Qzw7jS7boSaqYPw== X-Received: by 2002:a17:90a:cb98:: with SMTP id a24mr4494156pju.14.1617466973740; Sat, 03 Apr 2021 09:22:53 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:d1f5:1b96:f027:f646]) by smtp.gmail.com with ESMTPSA id 12sm11073718pgw.18.2021.04.03.09.22.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Apr 2021 09:22:53 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Sun, 4 Apr 2021 01:22:47 +0900 Message-Id: <20210403162247.1618154-1-hiroh@chromium.org> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3] android: CameraBuffer: Mark as invalid if cros::CameraBufferManager::Register() fails 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" cros::CameraBufferManager::Register() fails if a buffer handle is invalid. We should mark CameraBuffer as invalid on the failure of Register(). Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/android/mm/cros_camera_buffer.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) -- 2.31.0.208.g409f899ff0-goog 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