[v2] libcamera: Fix maybe-uninitialized error
diff mbox series

Message ID 20240628093643.2896445-1-stefan.klug@ideasonboard.com
State Accepted
Commit 9411578be8c84c9e5727dbde9e51a885c6e9fea1
Headers show
Series
  • [v2] libcamera: Fix maybe-uninitialized error
Related show

Commit Message

Stefan Klug June 28, 2024, 9:36 a.m. UTC
The gcc used in my current buildroot (Version 12.3) errors out with
-Wmaybe-uninitialized. Fix that.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
---
Changes in v2:
- Changed the error handling in AwbConfg::read as proposed by Naushir
- Removed unnecessary rewrapping of a comment

 src/ipa/libipa/exposure_mode_helper.cpp   | 9 +++------
 src/ipa/rpi/controller/rpi/awb.cpp        | 2 +-
 src/libcamera/device_enumerator_sysfs.cpp | 2 +-
 src/libcamera/pipeline/rpi/vc4/vc4.cpp    | 2 +-
 4 files changed, 6 insertions(+), 9 deletions(-)

Comments

Jacopo Mondi June 28, 2024, 10:08 a.m. UTC | #1
Hi Stefan

On Fri, Jun 28, 2024 at 11:36:02AM GMT, Stefan Klug wrote:
> The gcc used in my current buildroot (Version 12.3) errors out with
> -Wmaybe-uninitialized. Fix that.
>
> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
> Reviewed-by: Naushir Patuck <naush@raspberrypi.com>

Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>


> ---
> Changes in v2:
> - Changed the error handling in AwbConfg::read as proposed by Naushir
> - Removed unnecessary rewrapping of a comment
>
>  src/ipa/libipa/exposure_mode_helper.cpp   | 9 +++------
>  src/ipa/rpi/controller/rpi/awb.cpp        | 2 +-
>  src/libcamera/device_enumerator_sysfs.cpp | 2 +-
>  src/libcamera/pipeline/rpi/vc4/vc4.cpp    | 2 +-
>  4 files changed, 6 insertions(+), 9 deletions(-)
>
> diff --git a/src/ipa/libipa/exposure_mode_helper.cpp b/src/ipa/libipa/exposure_mode_helper.cpp
> index 683a564a01c8..7703becc4766 100644
> --- a/src/ipa/libipa/exposure_mode_helper.cpp
> +++ b/src/ipa/libipa/exposure_mode_helper.cpp
> @@ -166,7 +166,7 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const
>  		return { minShutter_, minGain_, exposure / (minShutter_ * minGain_) };
>
>  	utils::Duration shutter;
> -	double stageGain;
> +	double stageGain = 1.0;
>  	double gain;
>
>  	for (unsigned int stage = 0; stage < gains_.size(); stage++) {
> @@ -201,12 +201,9 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const
>  	 * From here on all we can do is max out the shutter time, followed by
>  	 * the analogue gain. If we still haven't achieved the target we send
>  	 * the rest of the exposure time to digital gain. If we were given no
> -	 * stages to use then set stageGain to 1.0 so that shutter time is maxed
> -	 * before gain touched at all.
> +	 * stages to use then the default stageGain of 1.0 is used so that
> +	 * shutter time is maxed before gain is touched at all.
>  	 */
> -	if (gains_.empty())
> -		stageGain = 1.0;
> -
>  	shutter = clampShutter(exposure / clampGain(stageGain));
>  	gain = clampGain(exposure / shutter);
>
> diff --git a/src/ipa/rpi/controller/rpi/awb.cpp b/src/ipa/rpi/controller/rpi/awb.cpp
> index 003c8fa137f3..f45525bce2d1 100644
> --- a/src/ipa/rpi/controller/rpi/awb.cpp
> +++ b/src/ipa/rpi/controller/rpi/awb.cpp
> @@ -122,7 +122,7 @@ int AwbConfig::read(const libcamera::YamlObject &params)
>  		}
>  		if (priors.empty()) {
>  			LOG(RPiAwb, Error) << "AwbConfig: no AWB priors configured";
> -			return ret;
> +			return -EINVAL;
>  		}
>  	}
>  	if (params.contains("modes")) {
> diff --git a/src/libcamera/device_enumerator_sysfs.cpp b/src/libcamera/device_enumerator_sysfs.cpp
> index fc33ba52b813..7866885c0f73 100644
> --- a/src/libcamera/device_enumerator_sysfs.cpp
> +++ b/src/libcamera/device_enumerator_sysfs.cpp
> @@ -33,7 +33,7 @@ int DeviceEnumeratorSysfs::init()
>  int DeviceEnumeratorSysfs::enumerate()
>  {
>  	struct dirent *ent;
> -	DIR *dir;
> +	DIR *dir = nullptr;
>
>  	static const char * const sysfs_dirs[] = {
>  		"/sys/subsystem/media/devices",
> diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp
> index 4a89e35f5d7b..e5b6ef2b37cd 100644
> --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp
> +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp
> @@ -802,7 +802,7 @@ void Vc4CameraData::ispInputDequeue(FrameBuffer *buffer)
>  void Vc4CameraData::ispOutputDequeue(FrameBuffer *buffer)
>  {
>  	RPi::Stream *stream = nullptr;
> -	unsigned int index;
> +	unsigned int index = 0;
>
>  	if (!isRunning())
>  		return;
> --
> 2.43.0
>

Patch
diff mbox series

diff --git a/src/ipa/libipa/exposure_mode_helper.cpp b/src/ipa/libipa/exposure_mode_helper.cpp
index 683a564a01c8..7703becc4766 100644
--- a/src/ipa/libipa/exposure_mode_helper.cpp
+++ b/src/ipa/libipa/exposure_mode_helper.cpp
@@ -166,7 +166,7 @@  ExposureModeHelper::splitExposure(utils::Duration exposure) const
 		return { minShutter_, minGain_, exposure / (minShutter_ * minGain_) };
 
 	utils::Duration shutter;
-	double stageGain;
+	double stageGain = 1.0;
 	double gain;
 
 	for (unsigned int stage = 0; stage < gains_.size(); stage++) {
@@ -201,12 +201,9 @@  ExposureModeHelper::splitExposure(utils::Duration exposure) const
 	 * From here on all we can do is max out the shutter time, followed by
 	 * the analogue gain. If we still haven't achieved the target we send
 	 * the rest of the exposure time to digital gain. If we were given no
-	 * stages to use then set stageGain to 1.0 so that shutter time is maxed
-	 * before gain touched at all.
+	 * stages to use then the default stageGain of 1.0 is used so that
+	 * shutter time is maxed before gain is touched at all.
 	 */
-	if (gains_.empty())
-		stageGain = 1.0;
-
 	shutter = clampShutter(exposure / clampGain(stageGain));
 	gain = clampGain(exposure / shutter);
 
diff --git a/src/ipa/rpi/controller/rpi/awb.cpp b/src/ipa/rpi/controller/rpi/awb.cpp
index 003c8fa137f3..f45525bce2d1 100644
--- a/src/ipa/rpi/controller/rpi/awb.cpp
+++ b/src/ipa/rpi/controller/rpi/awb.cpp
@@ -122,7 +122,7 @@  int AwbConfig::read(const libcamera::YamlObject &params)
 		}
 		if (priors.empty()) {
 			LOG(RPiAwb, Error) << "AwbConfig: no AWB priors configured";
-			return ret;
+			return -EINVAL;
 		}
 	}
 	if (params.contains("modes")) {
diff --git a/src/libcamera/device_enumerator_sysfs.cpp b/src/libcamera/device_enumerator_sysfs.cpp
index fc33ba52b813..7866885c0f73 100644
--- a/src/libcamera/device_enumerator_sysfs.cpp
+++ b/src/libcamera/device_enumerator_sysfs.cpp
@@ -33,7 +33,7 @@  int DeviceEnumeratorSysfs::init()
 int DeviceEnumeratorSysfs::enumerate()
 {
 	struct dirent *ent;
-	DIR *dir;
+	DIR *dir = nullptr;
 
 	static const char * const sysfs_dirs[] = {
 		"/sys/subsystem/media/devices",
diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp
index 4a89e35f5d7b..e5b6ef2b37cd 100644
--- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp
+++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp
@@ -802,7 +802,7 @@  void Vc4CameraData::ispInputDequeue(FrameBuffer *buffer)
 void Vc4CameraData::ispOutputDequeue(FrameBuffer *buffer)
 {
 	RPi::Stream *stream = nullptr;
-	unsigned int index;
+	unsigned int index = 0;
 
 	if (!isRunning())
 		return;