From patchwork Fri Apr 16 13:43:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11966 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 2DF23BD236 for ; Fri, 16 Apr 2021 13:43:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DE3296880C; Fri, 16 Apr 2021 15:43:55 +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="dsQDxwTT"; dkim-atps=neutral Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D445668806 for ; Fri, 16 Apr 2021 15:43:54 +0200 (CEST) Received: by mail-pl1-x632.google.com with SMTP id d8so13991620plh.11 for ; Fri, 16 Apr 2021 06:43:54 -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=IgHqUHcFx00U6vCUcgwUA1DSzfEZYqfcl1XNPvqalnk=; b=dsQDxwTTsWELeIR4om3ue+CyKchzrCCuWSCsBDPzaDswc/+SyznmkhX9mfvlcN05oy BWKcUTZ42/rh9IHOe4gA7dq5aCfiwIjlGdvGhox7mm1ee97qei9ACB2nyHy8tUwPMti+ s1NXh4Y7BZlZTwwN6bYqDpgfAWJo4/4MGbW0U= 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=IgHqUHcFx00U6vCUcgwUA1DSzfEZYqfcl1XNPvqalnk=; b=R+8m0mzpM1lTcUgv1aSpMtXvNvSmTTQbLPR/5Abd5k6h4XnebJh+bW4dyc1rtCAW8d dUFNJ76VQPF4RpW471AvGSplqFy1nY1wJGJWXyZYVo+B9T+rAKPsouzH32gb2haBuUgF tlTVj/0IuciLlLZ9b90yjms8lLl1OTSww53XBmVmjJwDaCppzNLzBGcwXN1m1bMfHefd yyQId1DGGfNsTCVf+qitSqsIpN+hCZAPM25RfW1mLrsV20iBKsYSmEyJ3ek2Q6dCoJeh Vj0w7ipDIx7BQ6eEcSW6v01hlsInjhZQzv8M8qokgMEAYHxKf9pqs4Xu/23B6nTP4Pf7 cFZg== X-Gm-Message-State: AOAM531wA40SZ4w7P00qab3V1X7C2ssuCZv11jbsWZHBUZJ4GEJmScxP Da+lqrGvzQV+w+j/x2aq4KQIV9bpox37tQ== X-Google-Smtp-Source: ABdhPJw1w8AO3cWhiUOB4tcubSP07Z09wO6n68nSs2sDnEC33BAkOGcaW2XBFes0Tyx1iH3YJvZ4Aw== X-Received: by 2002:a17:90a:7566:: with SMTP id q93mr9676034pjk.103.1618580632974; Fri, 16 Apr 2021 06:43:52 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:8518:74e8:412c:f22f]) by smtp.gmail.com with ESMTPSA id ms9sm6175606pjb.32.2021.04.16.06.43.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Apr 2021 06:43:52 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Fri, 16 Apr 2021 22:43:46 +0900 Message-Id: <20210416134347.2881373-1-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.368.gbe11c130af-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 | 8 ++++++++ src/android/mm/generic_camera_buffer.cpp | 9 +++++++++ 3 files changed, 23 insertions(+) diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h index 7e8970b4..21785a7e 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 buffer) \ +{ \ + return Private::isValidBuffer(buffer); \ +} \ 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..f06e8511 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,10 @@ size_t CameraBuffer::Private::jpegBufferSize(size_t maxJpegBufferSize) const return bufferManager_->GetPlaneSize(handle_, 0); } +/* static */ +bool CameraBuffer::Private::isValidBuffer(buffer_handle_t camera3Buffer) +{ + return cros::CameraBufferManager::IsValidBuffer(camera3Buffer); +} + PUBLIC_CAMERA_BUFFER_IMPLEMENTATION diff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp index 929e078a..07a07372 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 Fri Apr 16 13:43: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: 11967 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 906E4BD236 for ; Fri, 16 Apr 2021 13:43:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 532B86880A; Fri, 16 Apr 2021 15:43:58 +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="m9lXHJM3"; dkim-atps=neutral Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7CFB16880A for ; Fri, 16 Apr 2021 15:43:56 +0200 (CEST) Received: by mail-pg1-x535.google.com with SMTP id 31so3775603pgn.13 for ; Fri, 16 Apr 2021 06:43:56 -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=CZGaMpLSGBqWIYeKYD9P07cZ3KUZ0WaCTtrOPrRZLlA=; b=m9lXHJM3ujuubLPiJ/lnfqOQOeCNo/iv+qNnEte1kyldRtDxsV4wSvwaWn4pYne7Px L2spl1apYtFQh4EmhVol7w7FTvfqA//ovKdUIlFiiaBDz74lrqvfoxkolqweeGy7yP3D zoYytVM9b4mgMGB3dUR+4uBV72lFnhFQpXxPo= 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=CZGaMpLSGBqWIYeKYD9P07cZ3KUZ0WaCTtrOPrRZLlA=; b=UgSTBpC4d9qASvtCeGUD2ob7jMsQD+RyK9xAm94kkH90bIA3/6lKxBV4iONvrlk8Bu LdAsh/9HKPbzpxRb/mPP3duCKNI/ScHnOLiO8GIhqvSEjEi2maXQ4Hs3Eu5Gu6N2Xnsl bzprjcXyDVffsqxw1GmrSkbO89b937iANWQHcEV1T3bSdlcDihcOSzhrY7WUzSAak2DB I8MSaJjOSksHtbRw0aSv12sBijAMfZXzAgQTd5ytSgUfQQ06N3Smk8vM9gVc9x/6UI9s Sfuv5vhQGqn4bJSvXGp7TY34PmNxKo4oN3vSbn1iqlgH58sdezBcocbfxS0HRLXO5Uq6 8D7g== X-Gm-Message-State: AOAM533uDk73eKnld5jEzO3EAkSj5Ul5rL4o4fSofhRXewoFu9UciYFu +ovW8/n2v2nwKLTHXtHO1Em6UPx3pOaTIQ== X-Google-Smtp-Source: ABdhPJwihx17Os00JuRn/I9XBWDMMLSnwqtYYW4WB3XE0Dzs3LDyJnswXfSJFtepOnd2bvgDpB83dA== X-Received: by 2002:a63:36ce:: with SMTP id d197mr7989925pga.237.1618580634656; Fri, 16 Apr 2021 06:43:54 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:8518:74e8:412c:f22f]) by smtp.gmail.com with ESMTPSA id ms9sm6175606pjb.32.2021.04.16.06.43.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Apr 2021 06:43:54 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Fri, 16 Apr 2021 22:43:47 +0900 Message-Id: <20210416134347.2881373-2-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.368.gbe11c130af-goog In-Reply-To: <20210416134347.2881373-1-hiroh@chromium.org> References: <20210416134347.2881373-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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..7247c12c 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;