[libcamera-devel,2/3] libcamera: camera: Exclude streams whose configuration cannot be updated

Message ID 20200414070642.22366-3-email@uajain.com
State Superseded
Delegated to: Umang Jain
Headers show
Series
  • More Coverity scans fixes
Related show

Commit Message

Umang Jain April 14, 2020, 7:06 a.m. UTC
This prevents a null-deference below in the loop.

Pointed out by Coverity DefectId=279069

Signed-off-by: Umang Jain <email@uajain.com>
---
 src/libcamera/camera.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Laurent Pinchart April 14, 2020, 10:15 p.m. UTC | #1
Hi Umang,

Thank you for the patch.

On Tue, Apr 14, 2020 at 07:06:58AM +0000, Umang Jain wrote:
> This prevents a null-deference below in the loop.
> 
> Pointed out by Coverity DefectId=279069
> 
> Signed-off-by: Umang Jain <email@uajain.com>
> ---
>  src/libcamera/camera.cpp | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
> index 8c3bb2c..926e414 100644
> --- a/src/libcamera/camera.cpp
> +++ b/src/libcamera/camera.cpp
> @@ -777,9 +777,11 @@ int Camera::configure(CameraConfiguration *config)
>  	p_->activeStreams_.clear();
>  	for (const StreamConfiguration &cfg : *config) {
>  		Stream *stream = cfg.stream();
> -		if (!stream)
> +		if (!stream) {
>  			LOG(Camera, Fatal)
>  				<< "Pipeline handler failed to update stream configuration";
> +			continue;

Note that LOG(..., Fatal) calls std::abort(), so the program will
terminate. We are however considering only doing so in debug builds, so
fixing this issue is a good idea. However, I don't think such failure
should be ignored, the function should instead return an error
immediately. There may be a few things to cleanup before returning
though, to try and leave the Camera object in a valid state.

> +		}
>  
>  		stream->configuration_ = cfg;
>  		p_->activeStreams_.insert(stream);

Patch

diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
index 8c3bb2c..926e414 100644
--- a/src/libcamera/camera.cpp
+++ b/src/libcamera/camera.cpp
@@ -777,9 +777,11 @@  int Camera::configure(CameraConfiguration *config)
 	p_->activeStreams_.clear();
 	for (const StreamConfiguration &cfg : *config) {
 		Stream *stream = cfg.stream();
-		if (!stream)
+		if (!stream) {
 			LOG(Camera, Fatal)
 				<< "Pipeline handler failed to update stream configuration";
+			continue;
+		}
 
 		stream->configuration_ = cfg;
 		p_->activeStreams_.insert(stream);