From patchwork Thu Apr 8 03:10:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11864 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 750B4BD224 for ; Thu, 8 Apr 2021 03:10:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AC267687F4; Thu, 8 Apr 2021 05:10: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="Qgsmt3bm"; dkim-atps=neutral Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EE96468414 for ; Thu, 8 Apr 2021 05:10:56 +0200 (CEST) Received: by mail-pj1-x1036.google.com with SMTP id k23-20020a17090a5917b02901043e35ad4aso2352757pji.3 for ; Wed, 07 Apr 2021 20:10: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:mime-version :content-transfer-encoding; bh=tEJOL3o2NVXOZwxuu+1sdbqzp0ND1V2UzdVwclEipuA=; b=Qgsmt3bmGoO6DdDNYlTqSclc/lY81I0BjW0jNA1aRWWZi/YaTd4cnGfKgGok3s3ijU Ul4L1dxEnDfKkGMrFY5bNoUylzcgDGWmmNBkpQo52+OUNE4cZPDEVvtvPCKfJh1ikC3s D7p4LJK7N1fTEn+tzUio4iKRXUAUFOoxNudpg= 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=tEJOL3o2NVXOZwxuu+1sdbqzp0ND1V2UzdVwclEipuA=; b=CcaQe1ABPIY+v3eJWXqMtA/7IM7hhYNuVtAwfOsZhJyG4kyl8s3FggsnKsMqQ4xPvI N2sH0uG/58Jd0EB1sdPSygPgHc7dd5gPrnUu0IX4EWHet6wYRSqtm1yd+PfEyeJWJTVU +Qj/PILFLwV4bHm6RDP++gHE5d0pYH8pUwZv8ACw0La2MhZbVLjTk7LzyGAMJlQEBLqq NwkF5ETlYRmH9E7kLfjwJX0WPhoiQ5dzQLPokzTbNdMyzrSDI8/h0iGBo4QfzPSoXRtn vyWZgG/kcRk+So6bfU0Ryian4czc1h9x4pd5q+xNwsPOAs//oOD+g7S7LS3Z/Pwp26sE PzGg== X-Gm-Message-State: AOAM531EbFQ5UuRK5V9wXP7vVuSoWhwq7RbWDNOba8/BcPccJ+wQSO84 cFCh3uC1uYpB7oVGMxnV6qPfV+m0FHf8RQ== X-Google-Smtp-Source: ABdhPJw+NXMQX7KS0vbBt29QL/behJcGfgDXC3g8JKHHqT/RLHXk8tM3mg3eWmjJL/he1FmtR+INNQ== X-Received: by 2002:a17:902:24a:b029:e8:fe62:2840 with SMTP id 68-20020a170902024ab02900e8fe622840mr5891724plc.71.1617851454823; Wed, 07 Apr 2021 20:10:54 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:8822:ec6c:14d8:eea9]) by smtp.gmail.com with ESMTPSA id q14sm23685397pgt.54.2021.04.07.20.10.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Apr 2021 20:10:54 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 8 Apr 2021 12:10:39 +0900 Message-Id: <20210408031040.1388568-1-hiroh@chromium.org> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 | 18 ++++++++++++++++++ src/android/mm/generic_camera_buffer.cpp | 9 +++++++++ 3 files changed, 33 insertions(+) diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h index 7e8970b4..ade082c3 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_hanlde_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..f8449dfd 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,20 @@ 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..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 Thu Apr 8 03:10:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11865 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 411EFBD227 for ; Thu, 8 Apr 2021 03:11:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 34900687F3; Thu, 8 Apr 2021 05:10:59 +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="XWtcvKpy"; dkim-atps=neutral Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C84CB687A2 for ; Thu, 8 Apr 2021 05:10:57 +0200 (CEST) Received: by mail-pj1-x102c.google.com with SMTP id ot17-20020a17090b3b51b0290109c9ac3c34so2350054pjb.4 for ; Wed, 07 Apr 2021 20:10:57 -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=0kB3NhEX2dg7aQOxQ6JiJnUKmNOQIHWM9FgWV5zRdkQ=; b=XWtcvKpyfjyfKigk6YKy/04mweWp8n/G/HkbI5owD3P43jxuJ9cYYcCN46sQKp/v+H cP3ccXcrylxfOsQIRBaXyumO/64kBFm2XqBoL5DcPr6E+0IEBrVHzfUOUBatod7bknf7 e4ZXGWUCc2owP9r53H83OyU65Zpan90GOB5AI= 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=0kB3NhEX2dg7aQOxQ6JiJnUKmNOQIHWM9FgWV5zRdkQ=; b=Cn/SjsWAbUKgatIOL8pKS/yXfQiX9IVHAv8qW+QVlEQVLk0kOemHzXtiEO4v3LKdc8 YvhEqj9xDBQyDZoEyc2ypLCneouNpdNj8MfRO7YI3/BKlkAvDEBRs3pYW78UmkRX9plZ LpUQDd36lIQiUGU2PM01yLPYmLgGthZuvp+4t0SEj0dgYFrpOI2dDWnFLxbwpc3rWTrQ yFEYHWZvX4kDbQsLgDlEeKK4/Z+K16ZJ6iErqo/BWKtjaQmvZBC5leI3u13U5iXW9NzI oUFN1v1rRSORk6ksh2ageXWo1tcCsqVBmcc4rdmYsLJUAjDJ+rlZ+G/bdN3A26rs+0d4 kiYw== X-Gm-Message-State: AOAM531+2aCDCczfs+CYX9TJe8CksGcGceBNjuPCKbZQoGlR718ha3LG yCIMtuRKKMggVkGK6NJjIpK5CuNbbNuc/Q== X-Google-Smtp-Source: ABdhPJxFzh9BUPRNc4b8yJlBYw8rY5df99u0d5msick98Usszz6zRpAMMbjvt5U1kr+kaceY2TqKUg== X-Received: by 2002:a17:90a:b392:: with SMTP id e18mr6207040pjr.66.1617851456246; Wed, 07 Apr 2021 20:10:56 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:8822:ec6c:14d8:eea9]) by smtp.gmail.com with ESMTPSA id q14sm23685397pgt.54.2021.04.07.20.10.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Apr 2021 20:10:55 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 8 Apr 2021 12:10:40 +0900 Message-Id: <20210408031040.1388568-2-hiroh@chromium.org> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog In-Reply-To: <20210408031040.1388568-1-hiroh@chromium.org> References: <20210408031040.1388568-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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;