From patchwork Wed Apr 7 04:36:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11855 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 67DCABD695 for ; Wed, 7 Apr 2021 04:36:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CBB79687D5; Wed, 7 Apr 2021 06:36:29 +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="hoI86jhK"; dkim-atps=neutral Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 337E1602CD for ; Wed, 7 Apr 2021 06:36:28 +0200 (CEST) Received: by mail-pg1-x52f.google.com with SMTP id l76so12051983pga.6 for ; Tue, 06 Apr 2021 21:36:28 -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=R7HrEa+QGQ2YjpplnhmLYGq/Ic9JEtUOQu6cMCuTjxY=; b=hoI86jhK3DUcxLJ5IU+6LZbxaewghk2XKpGUr+BxzH+wEueorr/OcPVYuzjLfnn0b0 0UT/Frm4Ty6II4Bym21jU2IMW3grpO4kMR97P2IAX9RZsNp/DqdD3ByUgEV0xm0tEdOy 1u6xhPq9+vPEeFsXO5BCDG/RstNjnZ9GZFaG8= 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=R7HrEa+QGQ2YjpplnhmLYGq/Ic9JEtUOQu6cMCuTjxY=; b=Z6DlpkSM60HvABgHxEOP1SuwDbRMEYXI6Gx5fDCVNG68JUrM1IfBOE/zkYXFIIaNnQ byW7GIlgNPANhysk9FbhTFyaB0mzf8pNUqgb7WlD3Sk4AW1CDAruy+eqreQG4O+A2hGb KKdBte/fld49ADvNK97locVxw6pt38UchYEJMwpMVUXAkj2JdBVw7A3OtXTvigXU57LF 9dMsqP+6tkamn1HcsC/sOcCis8euSoFB7qeuf2D7h2Z5dvyJGrzbUlrlnpN+jzK7jOnU ssBhS2jA0VNUWHSQYoO3UVPJ0jQUr1TJ69UXp2SKlCWg8ul9cRs1IGIwvso4+9yzW5VB r3aw== X-Gm-Message-State: AOAM532W9vaVzHuuarQpisLjGRIJJlgxZ1oRl7mvR2JGyktTEJr24riw sYcNxBy3WRjmbW3VprYpg0OxikZyS/gerw== X-Google-Smtp-Source: ABdhPJygivTIYRlcBenuvNm+tLoWVnAMZ0bJfH4gC6ZsIcokgBNHadDGa2MfUiHaOVzNbH72CWgjUw== X-Received: by 2002:a62:1c8f:0:b029:209:7eb2:748f with SMTP id c137-20020a621c8f0000b02902097eb2748fmr1235159pfc.79.1617770186230; Tue, 06 Apr 2021 21:36:26 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:4180:40db:6f79:a143]) by smtp.gmail.com with ESMTPSA id d2sm19466967pgp.47.2021.04.06.21.36.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Apr 2021 21:36:25 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 7 Apr 2021 13:36:19 +0900 Message-Id: <20210407043620.1756347-1-hiroh@chromium.org> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/2] android: CameraBuffer: Add a static function to check a buffer validness 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" This adds a static function to CameraBuffer class that checks if a buffer_handle is valid with a platform dependent framework. For example, the function validates a buffer using cros::CameraBufferManager on ChromeOS. Signed-off-by: Hirokazu Honda Reviewed-by: Jacopo Mondi --- src/android/camera_buffer.h | 6 ++++++ src/android/mm/cros_camera_buffer.cpp | 19 +++++++++++++++++++ src/android/mm/generic_camera_buffer.cpp | 9 +++++++++ 3 files changed, 34 insertions(+) diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h index 7e8970b4..3bb9a435 100644 --- a/src/android/camera_buffer.h +++ b/src/android/camera_buffer.h @@ -20,6 +20,8 @@ public: CameraBuffer(buffer_handle_t camera3Buffer, int flags); ~CameraBuffer(); + static bool isValidBuffer(buffer_handle_t camera3Buffer); + bool isValid() const; unsigned int numPlanes() const; @@ -38,6 +40,10 @@ CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags) \ CameraBuffer::~CameraBuffer() \ { \ } \ +bool CameraBuffer::isValidBuffer(buffer_handle_t camera3Buffer) \ +{ \ + return Private::isValidBuffer(camera3Buffer); \ +} \ bool CameraBuffer::isValid() const \ { \ const Private *const d = LIBCAMERA_D_PTR(); \ diff --git a/src/android/mm/cros_camera_buffer.cpp b/src/android/mm/cros_camera_buffer.cpp index 1a4fd5d1..371a2511 100644 --- a/src/android/mm/cros_camera_buffer.cpp +++ b/src/android/mm/cros_camera_buffer.cpp @@ -24,6 +24,8 @@ public: buffer_handle_t camera3Buffer, int flags); ~Private(); + static bool isValidBuffer(buffer_handle_t camera3Buffer); + bool isValid() const { return valid_; } unsigned int numPlanes() const; @@ -133,4 +135,21 @@ size_t CameraBuffer::Private::jpegBufferSize(size_t maxJpegBufferSize) const return bufferManager_->GetPlaneSize(handle_, 0); } +// static +bool CameraBuffer::Private::isValidBuffer(buffer_handle_t camera3Buffer) +{ + cros::CameraBufferManager * bufferManager = + cros::CameraBufferManager::GetInstance(); + + int ret = bufferManager->Register(camera3Buffer); + if (ret) { + return false; + } + + bufferManager->Deregister(camera3Buffer); + + return true; +} + + PUBLIC_CAMERA_BUFFER_IMPLEMENTATION diff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp index 929e078a..0c52e196 100644 --- a/src/android/mm/generic_camera_buffer.cpp +++ b/src/android/mm/generic_camera_buffer.cpp @@ -24,6 +24,8 @@ public: buffer_handle_t camera3Buffer, int flags); ~Private(); + static bool isValidBuffer(buffer_handle_t camera3Buffer); + unsigned int numPlanes() const; Span plane(unsigned int plane); @@ -85,4 +87,11 @@ size_t CameraBuffer::Private::jpegBufferSize(size_t maxJpegBufferSize) const maxJpegBufferSize); } +// static +bool CameraBuffer::Private::isValidBuffer( + [[maybe_unused]] buffer_handle_t camera3Buffer) +{ + return true; + +} PUBLIC_CAMERA_BUFFER_IMPLEMENTATION From patchwork Wed Apr 7 04:36:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11856 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 75184BD695 for ; Wed, 7 Apr 2021 04:36:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 35FC0687DB; Wed, 7 Apr 2021 06:36:31 +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="m952RnXo"; dkim-atps=neutral Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7174E6879F for ; Wed, 7 Apr 2021 06:36:29 +0200 (CEST) Received: by mail-pj1-x1034.google.com with SMTP id z22-20020a17090a0156b029014d4056663fso650530pje.0 for ; Tue, 06 Apr 2021 21:36:29 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=n5Yvb32OqZp+I0yt8WUj7KhqsNdr2yErjMwK5nk0/0g=; b=m952RnXobrALknJWLZwwAJ4zFXd9WXAfGr3AMdVWnD0HcTB6JEr2N5mlivow7KqRGt dQ8HZT3HqPZ61SKdN/fCNAlSlf7eJmI/xNDeOxRqhAMOea8S2Quu90HqXC6GdsbuHOWJ GxxgNH47qMM0qwghGHKZXnlt7YHIsURaLP/4Q= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=n5Yvb32OqZp+I0yt8WUj7KhqsNdr2yErjMwK5nk0/0g=; b=Hl6ybK4jPcYJk4E+QBeIQXe3RkrW0YrHCxSpv5H1pJUbF1j5hxhEG+vGFQ/LK4ONsR 5RSqwqhEQPWFiP5R408LcZPmjS1TMFLZm49sZUcVcS1Gai/o1InKfPav5iC+e9gy1Psi rTSSM9PFCGNRmKxVxk7yheKeZFfXbSALetXAhmU6AwIrwwgUwEyvZARnXUq8JNuVu1eZ Ogr4jOpCA7UOmuBlbrjoMmHmk4noYcqH9/AtTzWA1azD60krqDgcbXfxBmeNr0EJm0Hs m6oLY6dtLnLLtMKaQ1q658jfNTAu7wlI/L2YtOKVOf1XkXjLrf9GSX+uVmDberZB8lh8 GLIQ== X-Gm-Message-State: AOAM5332AUVRvqzRfVtxe9BZKlDOrfxHuZr2gZaJrxg+Vtv1/Nhy7jt6 ojhTBesxeK4R+WfXFITLJ8OJpo/eU1yplA== X-Google-Smtp-Source: ABdhPJxIlvVFjqzFuAXSAWSI90VFywswpJVg7qWPhSMa6Qh3CTVU26IAyZqIprfjjIvG2mT3127Sog== X-Received: by 2002:a17:90a:6343:: with SMTP id v3mr1438562pjs.153.1617770187644; Tue, 06 Apr 2021 21:36:27 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:4180:40db:6f79:a143]) by smtp.gmail.com with ESMTPSA id d2sm19466967pgp.47.2021.04.06.21.36.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Apr 2021 21:36:27 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 7 Apr 2021 13:36:20 +0900 Message-Id: <20210407043620.1756347-2-hiroh@chromium.org> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog In-Reply-To: <20210407043620.1756347-1-hiroh@chromium.org> References: <20210407043620.1756347-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/2] android: CameraDevice: Validate buffer_handle by CameraBuffer::isValidBuffer() 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" This adds a validation to buffer_handle provided in CameraDevice::processCaptureRequest() by using CameraBuffer::isValidBuffer(). Signed-off-by: Hirokazu Honda Reviewed-by: Jacopo Mondi --- src/android/camera_device.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 89044efa..8a742812 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -293,6 +293,11 @@ bool isValidRequest(camera3_capture_request_t *camera3Request) << ") in buffer " << i; return false; } + + if (!CameraBuffer::isValidBuffer(handle)) { + LOG(HAL, Error) << "buffer " << i << "is invalid"; + return false; + } } return true;