[{"id":16094,"web_url":"https://patchwork.libcamera.org/comment/16094/","msgid":"<YGeqsGTkBng/kEQP@pendragon.ideasonboard.com>","date":"2021-04-02T23:37:20","subject":"Re: [libcamera-devel] [PATCH v3 1/2] android: cameraDevice:\n\tFactorize the code of validating camera3_capture_request","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Hiro,\n\nThank you for the patch.\n\nOn Fri, Apr 02, 2021 at 11:44:51AM +0900, Hirokazu Honda wrote:\n> CameraDevice::processCaptureRequest() checks the validness of a\n> provided camera3_capture_request. This factorizes the code in\n> order to add more validation to the request later.\n> \n> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>\n> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nI think we should go one step further on top of this though. Instead of\nsplitting request validation to a separate function, we could move it to\nthe Camera3RequestDescriptor class. Validation would happen in the\nconstructor, and a new isValid() function would then allow\nCameraDevice::processControls() to check if the request is valid. I'd\nthen turn Camera3RequestDescriptor into a class (it's a struct), and\nmove it out of CameraDevice to a camera_request.cpp file.\n\n> ---\n>  src/android/camera_device.cpp | 24 ++++++++++++++++--------\n>  1 file changed, 16 insertions(+), 8 deletions(-)\n> \n> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\n> index eb327978..988c1fd5 100644\n> --- a/src/android/camera_device.cpp\n> +++ b/src/android/camera_device.cpp\n> @@ -256,6 +256,21 @@ void sortCamera3StreamConfigs(std::vector<Camera3StreamConfig> &unsortedConfigs,\n>  \tunsortedConfigs = sortedConfigs;\n>  }\n>  \n> +bool isValidRequest(camera3_capture_request_t *camera3Request)\n> +{\n> +\tif (!camera3Request) {\n> +\t\tLOG(HAL, Error) << \"No capture request provided\";\n> +\t\treturn false;\n> +\t}\n> +\n> +\tif (!camera3Request->num_output_buffers) {\n> +\t\tLOG(HAL, Error) << \"No output buffers provided\";\n> +\t\treturn false;\n> +\t}\n> +\n> +\treturn true;\n> +}\n> +\n>  } /* namespace */\n>  \n>  /*\n> @@ -1785,15 +1800,8 @@ int CameraDevice::processControls(Camera3RequestDescriptor *descriptor)\n>  \n>  int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request)\n>  {\n> -\tif (!camera3Request) {\n> -\t\tLOG(HAL, Error) << \"No capture request provided\";\n> +\tif (isValidRequest(camera3Request))\n>  \t\treturn -EINVAL;\n> -\t}\n> -\n> -\tif (!camera3Request->num_output_buffers) {\n> -\t\tLOG(HAL, Error) << \"No output buffers provided\";\n> -\t\treturn -EINVAL;\n> -\t}\n>  \n>  \t/* Start the camera if that's the first request we handle. */\n>  \tif (!running_) {","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 85B70C0DA3\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  2 Apr 2021 23:38:07 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E21F5602D7;\n\tSat,  3 Apr 2021 01:38:06 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5523F602CF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  3 Apr 2021 01:38:05 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B0A1B3D7;\n\tSat,  3 Apr 2021 01:38:04 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"gUcLW2lI\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1617406684;\n\tbh=vApbx8A/yDsfrvK9e1jld6pGeNWVPmb3dKP6LRvy7xE=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=gUcLW2lIlvxHCFwuEjdo9TSK4GqZ41uQfaYd+JY+pouTQYAQp91WAzYEZfFh7KQw3\n\tVOrCLu5IDm3tnjVHm/Df7g30DCGTrnGk/zmIOxSaZnGjj7aW2BMWTSNSCV2jr734KE\n\tA4neIk5J2yAWRYxUNi4A1OZPE8SD8uCdI3Mcjvko=","Date":"Sat, 3 Apr 2021 02:37:20 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Hirokazu Honda <hiroh@chromium.org>","Message-ID":"<YGeqsGTkBng/kEQP@pendragon.ideasonboard.com>","References":"<20210402024452.1308253-1-hiroh@chromium.org>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20210402024452.1308253-1-hiroh@chromium.org>","Subject":"Re: [libcamera-devel] [PATCH v3 1/2] android: cameraDevice:\n\tFactorize the code of validating camera3_capture_request","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":16112,"web_url":"https://patchwork.libcamera.org/comment/16112/","msgid":"<CAO5uPHNx1h3-HnyxDFA6attCQixBvqG3KvTuUpYy8ZWWcLn7rw@mail.gmail.com>","date":"2021-04-03T13:27:21","subject":"Re: [libcamera-devel] [PATCH v3 1/2] android: cameraDevice:\n\tFactorize the code of validating camera3_capture_request","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/people/63/","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"content":"Hi Laurent,\n\nOn Sat, Apr 3, 2021 at 8:38 AM Laurent Pinchart\n<laurent.pinchart@ideasonboard.com> wrote:\n>\n> Hi Hiro,\n>\n> Thank you for the patch.\n>\n> On Fri, Apr 02, 2021 at 11:44:51AM +0900, Hirokazu Honda wrote:\n> > CameraDevice::processCaptureRequest() checks the validness of a\n> > provided camera3_capture_request. This factorizes the code in\n> > order to add more validation to the request later.\n> >\n> > Signed-off-by: Hirokazu Honda <hiroh@chromium.org>\n> > Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n> > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n>\n> I think we should go one step further on top of this though. Instead of\n> splitting request validation to a separate function, we could move it to\n> the Camera3RequestDescriptor class. Validation would happen in the\n> constructor, and a new isValid() function would then allow\n> CameraDevice::processControls() to check if the request is valid. I'd\n> then turn Camera3RequestDescriptor into a class (it's a struct), and\n> move it out of CameraDevice to a camera_request.cpp file.\n>\n\nThat sounds good to me.\nI am going to do another patch after this and \"leakage\" patch are landed.\n-Hiro\n\n> > ---\n> >  src/android/camera_device.cpp | 24 ++++++++++++++++--------\n> >  1 file changed, 16 insertions(+), 8 deletions(-)\n> >\n> > diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\n> > index eb327978..988c1fd5 100644\n> > --- a/src/android/camera_device.cpp\n> > +++ b/src/android/camera_device.cpp\n> > @@ -256,6 +256,21 @@ void sortCamera3StreamConfigs(std::vector<Camera3StreamConfig> &unsortedConfigs,\n> >       unsortedConfigs = sortedConfigs;\n> >  }\n> >\n> > +bool isValidRequest(camera3_capture_request_t *camera3Request)\n> > +{\n> > +     if (!camera3Request) {\n> > +             LOG(HAL, Error) << \"No capture request provided\";\n> > +             return false;\n> > +     }\n> > +\n> > +     if (!camera3Request->num_output_buffers) {\n> > +             LOG(HAL, Error) << \"No output buffers provided\";\n> > +             return false;\n> > +     }\n> > +\n> > +     return true;\n> > +}\n> > +\n> >  } /* namespace */\n> >\n> >  /*\n> > @@ -1785,15 +1800,8 @@ int CameraDevice::processControls(Camera3RequestDescriptor *descriptor)\n> >\n> >  int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request)\n> >  {\n> > -     if (!camera3Request) {\n> > -             LOG(HAL, Error) << \"No capture request provided\";\n> > +     if (isValidRequest(camera3Request))\n> >               return -EINVAL;\n> > -     }\n> > -\n> > -     if (!camera3Request->num_output_buffers) {\n> > -             LOG(HAL, Error) << \"No output buffers provided\";\n> > -             return -EINVAL;\n> > -     }\n> >\n> >       /* Start the camera if that's the first request we handle. */\n> >       if (!running_) {\n>\n> --\n> Regards,\n>\n> Laurent Pinchart","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 2EB12C0DA3\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat,  3 Apr 2021 13:27:35 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A80E36877E;\n\tSat,  3 Apr 2021 15:27:34 +0200 (CEST)","from mail-ed1-x533.google.com (mail-ed1-x533.google.com\n\t[IPv6:2a00:1450:4864:20::533])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 87108602CF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  3 Apr 2021 15:27:33 +0200 (CEST)","by mail-ed1-x533.google.com with SMTP id e7so7972722edu.10\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 03 Apr 2021 06:27:33 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"hELLQo7I\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=cB86cMbiubFb8/D3BRd4f1btFYmkEvR8u9FdJHi1fK4=;\n\tb=hELLQo7IG1MBiStpADneayPi7E6zsFp8aSXn2bX0UREB3/ADU6GUalGvQWjIIlUxaL\n\tFBfW705/Vc5fxXJ/pl7chRHiLE1xbZILaFSdLR6SRUypf7pdBFYnejLqQqPVK5afglTB\n\trw2Mmrj2iP0aSZ6eJeEi3RiWZO6KhaqjVAi6A=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=cB86cMbiubFb8/D3BRd4f1btFYmkEvR8u9FdJHi1fK4=;\n\tb=Zumg/QnhykCAV1QQjlYCrDjXwEXoth3SJ/ZLSimbGPNJGiZ7fz+LwpsryVJVUvBpcs\n\t6P33UN0n+rYCNqvPnWWvQ/PYB3PSwmZWF/BSgGp+zinB5GpMRzwCLo5gQnQQZYUYXaF7\n\tXyikf9T35YnzOO7BR36yRQAv2rJ0neHob1ViPpb335wMGLx2WFHvZlklPKokQ+7cPN11\n\tfmK3JY7/lYrjtrSCvAbm70bIHchVHuSnqa0n+GYyMRdvB63AmvshKC66T5DE+9nVL4za\n\trqu3LBELfODqJtXN4BBm0bPImeMKuoNmMjQIvPup48EVeT5MikdrK4Pd5vNylAEvOytH\n\t5Lww==","X-Gm-Message-State":"AOAM532FTvCJw6lvHcDvpX8hvdYsUkj6mA7T8lJyEA3H6lCCADqODOwG\n\tj4qSvw2T5l1jHNsPU713hdQezsYsqbzPbAgS7N8fVfHHY1s=","X-Google-Smtp-Source":"ABdhPJySMfQA6iS7okbapbNEFFvqpTEwReLagQQnJl2m/FuBlgGkjPZ8kizVdbEVM05pR0RF9NNUzSSP7VYxBpbpi3k=","X-Received":"by 2002:a05:6402:488:: with SMTP id\n\tk8mr20924470edv.233.1617456453158; \n\tSat, 03 Apr 2021 06:27:33 -0700 (PDT)","MIME-Version":"1.0","References":"<20210402024452.1308253-1-hiroh@chromium.org>\n\t<YGeqsGTkBng/kEQP@pendragon.ideasonboard.com>","In-Reply-To":"<YGeqsGTkBng/kEQP@pendragon.ideasonboard.com>","From":"Hirokazu Honda <hiroh@chromium.org>","Date":"Sat, 3 Apr 2021 22:27:21 +0900","Message-ID":"<CAO5uPHNx1h3-HnyxDFA6attCQixBvqG3KvTuUpYy8ZWWcLn7rw@mail.gmail.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v3 1/2] android: cameraDevice:\n\tFactorize the code of validating camera3_capture_request","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]