[libcamera-devel] [PATCH] cam: Use the common cleanup function on failure

paul.elder at ideasonboard.com paul.elder at ideasonboard.com
Tue Aug 4 04:27:19 CEST 2020


Hi Niklas,

Thank you for the patch.

On Tue, Aug 04, 2020 at 01:03:28AM +0200, Niklas Söderlund wrote:
> The different error paths in init() are out of sync. Instead of fixing
> them switch to using the cleanup() function which does to right thing in

s/does to right thing in/does the right thing/

> for all cases.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
> ---

Good catch.

Reviewed-by: Paul Elder <paul.elder at ideasonboard.com>

>  src/cam/main.cpp | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/src/cam/main.cpp b/src/cam/main.cpp
> index ec59e9eaf1176a94..6761d63801bd19af 100644
> --- a/src/cam/main.cpp
> +++ b/src/cam/main.cpp
> @@ -107,22 +107,23 @@ int CamApp::init(int argc, char **argv)
>  			std::cout << "Camera "
>  				  << std::string(options_[OptCamera])
>  				  << " not found" << std::endl;
> -			cm_->stop();
> +			cleanup();
>  			return -ENODEV;
>  		}
>  
>  		if (camera_->acquire()) {
>  			std::cout << "Failed to acquire camera" << std::endl;
> -			camera_.reset();
> -			cm_->stop();
> +			cleanup();
>  			return -EINVAL;
>  		}
>  
>  		std::cout << "Using camera " << camera_->name() << std::endl;
>  
>  		ret = prepareConfig();
> -		if (ret)
> +		if (ret) {
> +			cleanup();
>  			return ret;
> +		}
>  	}
>  
>  	if (options_.isSet(OptMonitor)) {
> -- 
> 2.28.0
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel at lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel


More information about the libcamera-devel mailing list