[RFC,1/1] camera_sensor: Ensure we try multiple camera sensor factories
diff mbox series

Message ID 20260204154015.3755120-2-isaac.scott@ideasonboard.com
State New
Headers show
Series
  • camera_sensor: Ensure we check all camera sensor factories
Related show

Commit Message

Isaac Scott Feb. 4, 2026, 3:40 p.m. UTC
CameraSensorFactory::match() should iterate through all available
camera sensor factories and in an attempt to find a CameraSensor class
that is suitable. Currently, it is implemented in such a way that it
will only try the first one before failing.

Remove the early return to ensure all CameraSensor factories are checked
before returning nullptr.

Signed-off-by: Isaac Scott <isaac.scott@ideasonboard.com>
---
 src/libcamera/sensor/camera_sensor.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Comments

Laurent Pinchart Feb. 4, 2026, 7:36 p.m. UTC | #1
Hi Isaac,

Thank you for the patch.

On Wed, Feb 04, 2026 at 03:40:15PM +0000, Isaac Scott wrote:
> CameraSensorFactory::match() should iterate through all available
> camera sensor factories and in an attempt to find a CameraSensor class
> that is suitable. Currently, it is implemented in such a way that it
> will only try the first one before failing.
>
> Remove the early return to ensure all CameraSensor factories are checked
> before returning nullptr.
> 
> Signed-off-by: Isaac Scott <isaac.scott@ideasonboard.com>
> ---
>  src/libcamera/sensor/camera_sensor.cpp | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/src/libcamera/sensor/camera_sensor.cpp b/src/libcamera/sensor/camera_sensor.cpp
> index 05390d1e1..42407b14b 100644
> --- a/src/libcamera/sensor/camera_sensor.cpp
> +++ b/src/libcamera/sensor/camera_sensor.cpp
> @@ -479,12 +479,10 @@ std::unique_ptr<CameraSensor> CameraSensorFactoryBase::create(MediaEntity *entit
>  			return std::get<std::unique_ptr<CameraSensor>>(std::move(result));
>  		}
>  
> -		if (std::get<int>(result)) {
> +		if (std::get<int>(result))
>  			LOG(CameraSensor, Error)
>  				<< "Failed to create sensor for '"
>  				<< entity->name() << ": " << std::get<int>(result);
> -			return nullptr;
> -		}

This is intentional, please see the documentation of the match function,
in the documentation of the REGISTER_CAMERA_SENSOR() macro. If a factory
determines that it should handle a camera sensor but fails to do so,
then no other factory is tried. A factory that determines it should not
handle a camera sensor returns 0, and the next factory is then tried.

>  	}
>  
>  	return nullptr;

Patch
diff mbox series

diff --git a/src/libcamera/sensor/camera_sensor.cpp b/src/libcamera/sensor/camera_sensor.cpp
index 05390d1e1..42407b14b 100644
--- a/src/libcamera/sensor/camera_sensor.cpp
+++ b/src/libcamera/sensor/camera_sensor.cpp
@@ -479,12 +479,10 @@  std::unique_ptr<CameraSensor> CameraSensorFactoryBase::create(MediaEntity *entit
 			return std::get<std::unique_ptr<CameraSensor>>(std::move(result));
 		}
 
-		if (std::get<int>(result)) {
+		if (std::get<int>(result))
 			LOG(CameraSensor, Error)
 				<< "Failed to create sensor for '"
 				<< entity->name() << ": " << std::get<int>(result);
-			return nullptr;
-		}
 	}
 
 	return nullptr;