From patchwork Thu Apr 1 15:31:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11816 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 0DB2BC0DA4 for ; Thu, 1 Apr 2021 15:31:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BB9A268784; Thu, 1 Apr 2021 17:31: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="leWC0ZKz"; 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 24F146877D for ; Thu, 1 Apr 2021 17:31:30 +0200 (CEST) Received: by mail-pl1-x632.google.com with SMTP id ay2so1205693plb.3 for ; Thu, 01 Apr 2021 08:31:30 -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=Y/PNzeU1fZsVFI4njw6I9n7gzV5T0/98dB/4QVM+76E=; b=leWC0ZKzV0OdYB/EsGoXOmrrXbanz50tjM667Gohty6EqGNdl+zdMlli9QkgA5S4nH XxoANZaDbB0WxsqGpjZxxNZF+oSydPoZ5sjruEPChQiU8aHa7FqhiDv14CZbT5HEFonQ xHVVVITOjSoa/tQJTWRc3HKxFeI8dSvoU2UbU= 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=Y/PNzeU1fZsVFI4njw6I9n7gzV5T0/98dB/4QVM+76E=; b=M6xWiH3U9tAlmFfH6r2TALKud34pU3URkAIGpnR/rDui3TsfCY4LzcbiNV3zW3At9D IHLMRlcg4Lntukw1GZcDFEOYHytgRZHev0k09odp/+eSW0Jd3/CE7aHwo+Ltu32Puj+q zE0n0fa20MTjUy2oFpH7eNE+sK7W9QyYyIHRJXHGPPmo3D2fInTXW3z6BrMljeS+WnYo eereZe+0ERjGT4FpOqNrqR6pYDjlQvL0raYHwgC1uaCvZFD96EIq5ZnaensagJ+wwOFU wFGB6eSqGLIxlgZyz6xzQ9q0bw07eOMvNUcl2GjQ9KzTkjUtaAjJGaQUYGE4SsTDbwRs 2VzQ== X-Gm-Message-State: AOAM533nNK9dGVW0gFoBFE3mJhwI83uTD32+NGh44tWz1kfyYvMDe/JX d0byp1mTqskTT5wahmNGjH8Vfvtw0ywmag== X-Google-Smtp-Source: ABdhPJyMtsvcvAH17B/A2GmBPC5Kfa6enzBJqV0Jr/9rBg+q3hx6jrlnnjB1vEq9/8ptAdSWd4VaRg== X-Received: by 2002:a17:90b:fce:: with SMTP id gd14mr9159500pjb.64.1617291088458; Thu, 01 Apr 2021 08:31:28 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:908:1da:b07c:32bc]) by smtp.gmail.com with ESMTPSA id y68sm6521573pgy.5.2021.04.01.08.31.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Apr 2021 08:31:27 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Fri, 2 Apr 2021 00:31:22 +0900 Message-Id: <20210401153123.1217170-1-hiroh@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] android: cameraDevice: Factorize the code of validating camera3_capture_request 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" CameraDevice::processCaptureRequest() checks the validness of a provided camera3_capture_request. This factorizes the code in order to add more validation to the request later. Signed-off-by: Hirokazu Honda Reviewed-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- src/android/camera_device.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index eb327978..48eb471d 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -256,6 +256,21 @@ void sortCamera3StreamConfigs(std::vector &unsortedConfigs, unsortedConfigs = sortedConfigs; } +bool isValidRequest(camera3_capture_request_t *camera3Request) +{ + if (!camera3Request) { + LOG(HAL, Error) << "No capture request provided"; + return false; + } + + if (!camera3Request->num_output_buffers) { + LOG(HAL, Error) << "No output buffers provided"; + return -EINVAL; + } + + return true; +} + } /* namespace */ /* @@ -1785,15 +1800,8 @@ int CameraDevice::processControls(Camera3RequestDescriptor *descriptor) int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request) { - if (!camera3Request) { - LOG(HAL, Error) << "No capture request provided"; - return -EINVAL; - } - - if (!camera3Request->num_output_buffers) { - LOG(HAL, Error) << "No output buffers provided"; + if (isValidRequest(camera3Request)) return -EINVAL; - } /* Start the camera if that's the first request we handle. */ if (!running_) {