[libcamera-devel,v6,3/7] libcamera: camera: Don't call freeBuffer() on allocateBuffer() error

Message ID 20190416134210.21097-4-jacopo@jmondi.org
State Superseded
Headers show
Series
  • libcamera: Framework changes to prepare for multiple streams support
Related show

Commit Message

Jacopo Mondi April 16, 2019, 1:42 p.m. UTC
Do not assume the freeBuffer() function can handle allocateBuffer()
method failures, as error handling and clean up should be performed
by allocateBuffer() method itself.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/libcamera/camera.cpp | 1 -
 1 file changed, 1 deletion(-)

Comments

Niklas Söderlund April 16, 2019, 7:42 p.m. UTC | #1
Hi Jacopo,

Thanks for your work.

On 2019-04-16 15:42:06 +0200, Jacopo Mondi wrote:
> Do not assume the freeBuffer() function can handle allocateBuffer()
> method failures, as error handling and clean up should be performed
> by allocateBuffer() method itself.
> 
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

> ---
>  src/libcamera/camera.cpp | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
> index 21caa24b90b5..2d0a80664214 100644
> --- a/src/libcamera/camera.cpp
> +++ b/src/libcamera/camera.cpp
> @@ -650,7 +650,6 @@ int Camera::allocateBuffers()
>  	int ret = pipe_->allocateBuffers(this, activeStreams_);
>  	if (ret) {
>  		LOG(Camera, Error) << "Failed to allocate buffers";
> -		freeBuffers();
>  		return ret;
>  	}
>  
> -- 
> 2.21.0
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
Laurent Pinchart April 16, 2019, 10:11 p.m. UTC | #2
Hi Jacopo,

Thank you for the patch.

On Tue, Apr 16, 2019 at 03:42:06PM +0200, Jacopo Mondi wrote:
> Do not assume the freeBuffer() function can handle allocateBuffer()
> method failures, as error handling and clean up should be performed
> by allocateBuffer() method itself.
> 
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

I would however squash this with patch 2/7 as the freeBuffers() call is
added there.

> ---
>  src/libcamera/camera.cpp | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
> index 21caa24b90b5..2d0a80664214 100644
> --- a/src/libcamera/camera.cpp
> +++ b/src/libcamera/camera.cpp
> @@ -650,7 +650,6 @@ int Camera::allocateBuffers()
>  	int ret = pipe_->allocateBuffers(this, activeStreams_);
>  	if (ret) {
>  		LOG(Camera, Error) << "Failed to allocate buffers";
> -		freeBuffers();
>  		return ret;
>  	}
>
Laurent Pinchart April 16, 2019, 10:15 p.m. UTC | #3
Hi Jacopo,

On Wed, Apr 17, 2019 at 01:11:21AM +0300, Laurent Pinchart wrote:
> On Tue, Apr 16, 2019 at 03:42:06PM +0200, Jacopo Mondi wrote:
> > Do not assume the freeBuffer() function can handle allocateBuffer()
> > method failures, as error handling and clean up should be performed
> > by allocateBuffer() method itself.
> > 
> > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> I would however squash this with patch 2/7 as the freeBuffers() call is
> added there.

Actually, don't you also need to fix
PipelineHandlerIPU3::allocateBuffers() to cleanup in case of error ?

> > ---
> >  src/libcamera/camera.cpp | 1 -
> >  1 file changed, 1 deletion(-)
> > 
> > diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
> > index 21caa24b90b5..2d0a80664214 100644
> > --- a/src/libcamera/camera.cpp
> > +++ b/src/libcamera/camera.cpp
> > @@ -650,7 +650,6 @@ int Camera::allocateBuffers()
> >  	int ret = pipe_->allocateBuffers(this, activeStreams_);
> >  	if (ret) {
> >  		LOG(Camera, Error) << "Failed to allocate buffers";
> > -		freeBuffers();
> >  		return ret;
> >  	}
> >

Patch

diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
index 21caa24b90b5..2d0a80664214 100644
--- a/src/libcamera/camera.cpp
+++ b/src/libcamera/camera.cpp
@@ -650,7 +650,6 @@  int Camera::allocateBuffers()
 	int ret = pipe_->allocateBuffers(this, activeStreams_);
 	if (ret) {
 		LOG(Camera, Error) << "Failed to allocate buffers";
-		freeBuffers();
 		return ret;
 	}