[{"id":1438,"web_url":"https://patchwork.libcamera.org/comment/1438/","msgid":"<20190417153535.GM28515@bigcity.dyn.berto.se>","date":"2019-04-17T15:35:35","subject":"Re: [libcamera-devel] [PATCH v7 3/8] libcamera: camera: Don't call\n\tfreeBuffer() on allocateBuffer() error","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Jacopo,\n\nThanks for your work.\n\nOn 2019-04-17 15:58:53 +0200, Jacopo Mondi wrote:\n> Do not assume the freeBuffer() function can handle allocateBuffer()\n> method failures, as error handling and clean up should be performed\n> by allocateBuffer() method itself.\n> \n> Perform clean-up on allocations failures in the IPU3 pipeline handler,\n> now that freeBuffers() is not called anymore.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  src/libcamera/camera.cpp             |  1 -\n>  src/libcamera/pipeline/ipu3/ipu3.cpp | 19 ++++++++++++++-----\n>  2 files changed, 14 insertions(+), 6 deletions(-)\n> \n> diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\n> index 21caa24b90b5..2d0a80664214 100644\n> --- a/src/libcamera/camera.cpp\n> +++ b/src/libcamera/camera.cpp\n> @@ -650,7 +650,6 @@ int Camera::allocateBuffers()\n>  \tint ret = pipe_->allocateBuffers(this, activeStreams_);\n>  \tif (ret) {\n>  \t\tLOG(Camera, Error) << \"Failed to allocate buffers\";\n> -\t\tfreeBuffers();\n>  \t\treturn ret;\n>  \t}\n>  \n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index f96e8763bce9..6e093fc22259 100644\n> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -314,6 +314,7 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera,\n>  \tStream *stream = *streams.begin();\n>  \tCIO2Device *cio2 = &data->cio2_;\n>  \tImgUDevice *imgu = data->imgu_;\n> +\tunsigned int bufferCount;\n>  \tint ret;\n>  \n>  \t/* Share buffers between CIO2 output and ImgU input. */\n> @@ -323,31 +324,39 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera,\n>  \n>  \tret = imgu->importBuffers(pool);\n>  \tif (ret)\n> -\t\treturn ret;\n> +\t\tgoto error_free_cio2;\n>  \n>  \t/* Export ImgU output buffers to the stream's pool. */\n>  \tret = imgu->exportBuffers(&imgu->output_, &stream->bufferPool());\n>  \tif (ret)\n> -\t\treturn ret;\n> +\t\tgoto error_free_imgu;\n>  \n>  \t/*\n>  \t * Reserve memory in viewfinder and stat output devices. Use the\n>  \t * same number of buffers as the ones requested for the output\n>  \t * stream.\n>  \t */\n> -\tunsigned int bufferCount = stream->bufferPool().count();\n> +\tbufferCount = stream->bufferPool().count();\n>  \n>  \timgu->viewfinder_.pool->createBuffers(bufferCount);\n>  \tret = imgu->exportBuffers(&imgu->viewfinder_, imgu->viewfinder_.pool);\n>  \tif (ret)\n> -\t\treturn ret;\n> +\t\tgoto error_free_imgu;\n>  \n>  \timgu->stat_.pool->createBuffers(bufferCount);\n>  \tret = imgu->exportBuffers(&imgu->stat_, imgu->stat_.pool);\n>  \tif (ret)\n> -\t\treturn ret;\n> +\t\tgoto error_free_imgu;\n>  \n>  \treturn 0;\n> +\n> +error_free_imgu:\n> +\timgu->freeBuffers();\n> +\n> +error_free_cio2:\n> +\tcio2->freeBuffers();\n> +\n> +\treturn ret;\n>  }\n>  \n>  int PipelineHandlerIPU3::freeBuffers(Camera *camera,\n> -- \n> 2.21.0\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com\n\t[IPv6:2a00:1450:4864:20::12f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0491960DBF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 17 Apr 2019 17:35:38 +0200 (CEST)","by mail-lf1-x12f.google.com with SMTP id w23so19192447lfc.9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 17 Apr 2019 08:35:37 -0700 (PDT)","from localhost (89-233-230-99.cust.bredband2.com. [89.233.230.99])\n\tby smtp.gmail.com with ESMTPSA id\n\td3sm10790720ljc.15.2019.04.17.08.35.36\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tWed, 17 Apr 2019 08:35:36 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=WNSM97EXgTc2OkyuuQm6jkBGnS9p8v2UBd+WRJyZ+Mk=;\n\tb=w4Z8alLrf2rhuypOK3Csbz1L2IcLbEKC9eZchmQ9lGh5uvkZVIyocPi4KgYw0/bsON\n\thPNi6vghKO+Spz/W6KpYJwZu2xz+2V6qMkV0Mf1wezg7Ua7oN/jK5CiVV+nBzI+EIfPK\n\tGl53TFwdXbg8AOtCrZgzIFMpVhUaTvhCiArwRh5KwaowAHFVF3xIi8sinvrmL6TzkGtg\n\t5+Q30Q5LAevg0xvcd8MHpowDrhGWi5z0fiqn2aEJg086FqJdqKPOMgX/qMxMhrRIfg7v\n\t6MDgPnqkZaAyzgSvsNG7dMlWt6akbpkLDhTMKy19gnyRs2fCGbXahfaZwS9SKrce+srT\n\tTMdg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=WNSM97EXgTc2OkyuuQm6jkBGnS9p8v2UBd+WRJyZ+Mk=;\n\tb=s+X8HZM9gIGWaplMWvXwkAw7mO1sSM2g+C5eiB/NRZ60dm15s5bAowM3PKkW2+T8zU\n\tkSrALN59Zi6qqm3zWql7SmPiiRASvs7kHQ83rWBhj3Ib768FzSZijENnm4TZNqBNcBTO\n\tYmeQb8S/wgNui9+/DDGcAPWRPJ9SDDZYzTg+UGPtoG0d2l6yGAyFtM1BhNFnHDZ7RyA4\n\tGRZPIaa9485PnwGbwIg3GnM7y2g2KvS+kpwNACg7Nv1PmcXu/FWzqgFB+cG2o+rUP/wN\n\tFAAZMMoHdfhyP9lb5fMJFzSnLT5Zkm1T9c1iJldkFRxLSCWRgeAABNTA0t4RXFmuQEUL\n\teD7A==","X-Gm-Message-State":"APjAAAXUAx+h4iitqtUT3WJafRaIPmrjlH3rAsPalfjIGJXtYL2dS3kj\n\t3qJNVpVUuLDX8fjmzTKmzpiq3A==","X-Google-Smtp-Source":"APXvYqyN4/SFF1UOUqzAXf90QCtrcjiZHbrczAPl8V3vs8dYV7tXZZl27plnhjME9HLdPQrS/lNCYw==","X-Received":"by 2002:a19:ee17:: with SMTP id\n\tg23mr14953697lfb.43.1555515337008; \n\tWed, 17 Apr 2019 08:35:37 -0700 (PDT)","Date":"Wed, 17 Apr 2019 17:35:35 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190417153535.GM28515@bigcity.dyn.berto.se>","References":"<20190417135858.23914-1-jacopo@jmondi.org>\n\t<20190417135858.23914-4-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190417135858.23914-4-jacopo@jmondi.org>","User-Agent":"Mutt/1.11.3 (2019-02-01)","Subject":"Re: [libcamera-devel] [PATCH v7 3/8] libcamera: camera: Don't call\n\tfreeBuffer() on allocateBuffer() error","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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>","X-List-Received-Date":"Wed, 17 Apr 2019 15:35:38 -0000"}},{"id":1446,"web_url":"https://patchwork.libcamera.org/comment/1446/","msgid":"<20190418124747.GM4806@pendragon.ideasonboard.com>","date":"2019-04-18T12:47:47","subject":"Re: [libcamera-devel] [PATCH v7 3/8] libcamera: camera: Don't call\n\tfreeBuffer() on allocateBuffer() error","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Wed, Apr 17, 2019 at 03:58:53PM +0200, Jacopo Mondi wrote:\n> Do not assume the freeBuffer() function can handle allocateBuffer()\n> method failures, as error handling and clean up should be performed\n> by allocateBuffer() method itself.\n> \n> Perform clean-up on allocations failures in the IPU3 pipeline handler,\n> now that freeBuffers() is not called anymore.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  src/libcamera/camera.cpp             |  1 -\n>  src/libcamera/pipeline/ipu3/ipu3.cpp | 19 ++++++++++++++-----\n>  2 files changed, 14 insertions(+), 6 deletions(-)\n> \n> diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\n> index 21caa24b90b5..2d0a80664214 100644\n> --- a/src/libcamera/camera.cpp\n> +++ b/src/libcamera/camera.cpp\n> @@ -650,7 +650,6 @@ int Camera::allocateBuffers()\n>  \tint ret = pipe_->allocateBuffers(this, activeStreams_);\n>  \tif (ret) {\n>  \t\tLOG(Camera, Error) << \"Failed to allocate buffers\";\n> -\t\tfreeBuffers();\n>  \t\treturn ret;\n>  \t}\n>  \n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index f96e8763bce9..6e093fc22259 100644\n> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -314,6 +314,7 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera,\n>  \tStream *stream = *streams.begin();\n>  \tCIO2Device *cio2 = &data->cio2_;\n>  \tImgUDevice *imgu = data->imgu_;\n> +\tunsigned int bufferCount;\n>  \tint ret;\n>  \n>  \t/* Share buffers between CIO2 output and ImgU input. */\n> @@ -323,31 +324,39 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera,\n>  \n>  \tret = imgu->importBuffers(pool);\n>  \tif (ret)\n> -\t\treturn ret;\n> +\t\tgoto error_free_cio2;\n>  \n>  \t/* Export ImgU output buffers to the stream's pool. */\n>  \tret = imgu->exportBuffers(&imgu->output_, &stream->bufferPool());\n>  \tif (ret)\n> -\t\treturn ret;\n> +\t\tgoto error_free_imgu;\n>  \n>  \t/*\n>  \t * Reserve memory in viewfinder and stat output devices. Use the\n>  \t * same number of buffers as the ones requested for the output\n>  \t * stream.\n>  \t */\n> -\tunsigned int bufferCount = stream->bufferPool().count();\n> +\tbufferCount = stream->bufferPool().count();\n>  \n>  \timgu->viewfinder_.pool->createBuffers(bufferCount);\n>  \tret = imgu->exportBuffers(&imgu->viewfinder_, imgu->viewfinder_.pool);\n>  \tif (ret)\n> -\t\treturn ret;\n> +\t\tgoto error_free_imgu;\n>  \n>  \timgu->stat_.pool->createBuffers(bufferCount);\n>  \tret = imgu->exportBuffers(&imgu->stat_, imgu->stat_.pool);\n>  \tif (ret)\n> -\t\treturn ret;\n> +\t\tgoto error_free_imgu;\n>  \n>  \treturn 0;\n> +\n> +error_free_imgu:\n> +\timgu->freeBuffers();\n> +\n> +error_free_cio2:\n> +\tcio2->freeBuffers();\n\nGiven that in the case of the IPU3 the freeBuffers() functions can be\ncalled unconditionally even when buffers haven't been allocated, you\ncould have\n\nerror:\n\tfreeBuffers();\n\nUp to you.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\n> +\treturn ret;\n>  }\n>  \n>  int PipelineHandlerIPU3::freeBuffers(Camera *camera,","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AEECA60DC0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Apr 2019 14:47:56 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 04C30333;\n\tThu, 18 Apr 2019 14:47:55 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1555591676;\n\tbh=6vdp/nPcvtxJFAZQqakAIFExs2Ywh7vegWYxkUb5L3Q=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=tNz4HM6ex7rskDNROSYFsI/t0rPliq3tcGmieU45mtyIrDnEpFCnzU/jvlrxdqZTr\n\trysew1iGRzKZ3hfWraDtHFHbiRwDdsGfhDunA3SxW9sImx0S0T4imN0p7HE8IN4qBG\n\tW9Iu3y6C8sff65cSCGYrcNwP8ArUD2vKCxGn79Y8=","Date":"Thu, 18 Apr 2019 15:47:47 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190418124747.GM4806@pendragon.ideasonboard.com>","References":"<20190417135858.23914-1-jacopo@jmondi.org>\n\t<20190417135858.23914-4-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190417135858.23914-4-jacopo@jmondi.org>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v7 3/8] libcamera: camera: Don't call\n\tfreeBuffer() on allocateBuffer() error","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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>","X-List-Received-Date":"Thu, 18 Apr 2019 12:47:56 -0000"}}]