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

Message ID 20200803230328.1125040-1-niklas.soderlund@ragnatech.se
State Accepted
Commit 1074604c9e2b6d9afa0247f2ca62b3140131d639
Headers show
Series
  • [libcamera-devel] cam: Use the common cleanup function on failure
Related show

Commit Message

Niklas Söderlund Aug. 3, 2020, 11:03 p.m. UTC
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
for all cases.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 src/cam/main.cpp | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Paul Elder Aug. 4, 2020, 2:27 a.m. UTC | #1
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@ragnatech.se>
> ---

Good catch.

Reviewed-by: Paul Elder <paul.elder@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@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch

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)) {