[libcamera-devel,04/10] libcamera: pipeline: Prevent variable aliasing
diff mbox series

Message ID 20201013151241.3557005-5-kieran.bingham@ideasonboard.com
State Superseded
Headers show
Series
  • Shadowed Variables
Related show

Commit Message

Kieran Bingham Oct. 13, 2020, 3:12 p.m. UTC
Remove variable aliasing within the pipeline handler implementations.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 6 +++---
 src/libcamera/pipeline/simple/converter.cpp        | 8 ++++----
 src/libcamera/pipeline/simple/simple.cpp           | 4 ++--
 src/libcamera/pipeline/uvcvideo/uvcvideo.cpp       | 4 ++--
 4 files changed, 11 insertions(+), 11 deletions(-)

Comments

Niklas Söderlund Oct. 14, 2020, 12:25 p.m. UTC | #1
Hi Kieran,

On 2020-10-13 16:12:35 +0100, Kieran Bingham wrote:
> Remove variable aliasing within the pipeline handler implementations.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

> ---
>  src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 6 +++---
>  src/libcamera/pipeline/simple/converter.cpp        | 8 ++++----
>  src/libcamera/pipeline/simple/simple.cpp           | 4 ++--
>  src/libcamera/pipeline/uvcvideo/uvcvideo.cpp       | 4 ++--
>  4 files changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> index 26dbd2573e04..85e0a1f26ab6 100644
> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> @@ -512,9 +512,9 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,
>  		/* Translate the V4L2PixelFormat to PixelFormat. */
>  		std::map<PixelFormat, std::vector<SizeRange>> deviceFormats;
>  		for (const auto &format : fmts) {
> -			PixelFormat pixelFormat = format.first.toPixelFormat();
> -			if (pixelFormat.isValid())
> -				deviceFormats[pixelFormat] = format.second;
> +			PixelFormat pf = format.first.toPixelFormat();
> +			if (pf.isValid())
> +				deviceFormats[pf] = format.second;
>  		}
>  
>  		/* Add the stream format based on the device node used for the use case. */
> diff --git a/src/libcamera/pipeline/simple/converter.cpp b/src/libcamera/pipeline/simple/converter.cpp
> index 75fb297ebd58..2b541cd2bb3f 100644
> --- a/src/libcamera/pipeline/simple/converter.cpp
> +++ b/src/libcamera/pipeline/simple/converter.cpp
> @@ -72,11 +72,11 @@ std::vector<PixelFormat> SimpleConverter::formats(PixelFormat input)
>  	 * Set the format on the input side (V4L2 output) of the converter to
>  	 * enumerate the conversion capabilities on its output (V4L2 capture).
>  	 */
> -	V4L2DeviceFormat format;
> -	format.fourcc = m2m_->output()->toV4L2PixelFormat(input);
> -	format.size = { 1, 1 };
> +	V4L2DeviceFormat v4l2Format;
> +	v4l2Format.fourcc = m2m_->output()->toV4L2PixelFormat(input);
> +	v4l2Format.size = { 1, 1 };
>  
> -	int ret = m2m_->output()->setFormat(&format);
> +	int ret = m2m_->output()->setFormat(&v4l2Format);
>  	if (ret < 0) {
>  		LOG(SimplePipeline, Error)
>  			<< "Failed to set format: " << strerror(-ret);
> diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
> index 7adb17e2d1db..999c44515023 100644
> --- a/src/libcamera/pipeline/simple/simple.cpp
> +++ b/src/libcamera/pipeline/simple/simple.cpp
> @@ -314,8 +314,8 @@ int SimpleCameraData::init()
>  
>  			config.outputSizes = converter->sizes(format.size);
>  
> -			for (PixelFormat format : converter->formats(pixelFormat))
> -				formats_[format] = config;
> +			for (PixelFormat fmt : converter->formats(pixelFormat))
> +				formats_[fmt] = config;
>  		}
>  	}
>  
> diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> index 8ec0dac1e689..54ba1b87bb3e 100644
> --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> @@ -490,8 +490,8 @@ int UVCCameraData::init(MediaDevice *media)
>  	/* Locate and initialise the camera data with the default video node. */
>  	const std::vector<MediaEntity *> &entities = media->entities();
>  	auto entity = std::find_if(entities.begin(), entities.end(),
> -				   [](MediaEntity *entity) {
> -					   return entity->flags() & MEDIA_ENT_FL_DEFAULT;
> +				   [](MediaEntity *e) {
> +					   return e->flags() & MEDIA_ENT_FL_DEFAULT;
>  				   });
>  	if (entity == entities.end()) {
>  		LOG(UVC, Error) << "Could not find a default video device";
> -- 
> 2.25.1
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
Laurent Pinchart Oct. 15, 2020, 1:28 p.m. UTC | #2
Hi Kieran,

Thank you for the patch.

On Tue, Oct 13, 2020 at 04:12:35PM +0100, Kieran Bingham wrote:
> Remove variable aliasing within the pipeline handler implementations.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 6 +++---
>  src/libcamera/pipeline/simple/converter.cpp        | 8 ++++----
>  src/libcamera/pipeline/simple/simple.cpp           | 4 ++--
>  src/libcamera/pipeline/uvcvideo/uvcvideo.cpp       | 4 ++--
>  4 files changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> index 26dbd2573e04..85e0a1f26ab6 100644
> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> @@ -512,9 +512,9 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,
>  		/* Translate the V4L2PixelFormat to PixelFormat. */
>  		std::map<PixelFormat, std::vector<SizeRange>> deviceFormats;
>  		for (const auto &format : fmts) {
> -			PixelFormat pixelFormat = format.first.toPixelFormat();
> -			if (pixelFormat.isValid())
> -				deviceFormats[pixelFormat] = format.second;
> +			PixelFormat pf = format.first.toPixelFormat();
> +			if (pf.isValid())
> +				deviceFormats[pf] = format.second;
>  		}
>  
>  		/* Add the stream format based on the device node used for the use case. */
> diff --git a/src/libcamera/pipeline/simple/converter.cpp b/src/libcamera/pipeline/simple/converter.cpp
> index 75fb297ebd58..2b541cd2bb3f 100644
> --- a/src/libcamera/pipeline/simple/converter.cpp
> +++ b/src/libcamera/pipeline/simple/converter.cpp
> @@ -72,11 +72,11 @@ std::vector<PixelFormat> SimpleConverter::formats(PixelFormat input)
>  	 * Set the format on the input side (V4L2 output) of the converter to
>  	 * enumerate the conversion capabilities on its output (V4L2 capture).
>  	 */
> -	V4L2DeviceFormat format;
> -	format.fourcc = m2m_->output()->toV4L2PixelFormat(input);
> -	format.size = { 1, 1 };
> +	V4L2DeviceFormat v4l2Format;
> +	v4l2Format.fourcc = m2m_->output()->toV4L2PixelFormat(input);
> +	v4l2Format.size = { 1, 1 };
>  
> -	int ret = m2m_->output()->setFormat(&format);
> +	int ret = m2m_->output()->setFormat(&v4l2Format);
>  	if (ret < 0) {
>  		LOG(SimplePipeline, Error)
>  			<< "Failed to set format: " << strerror(-ret);
> diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
> index 7adb17e2d1db..999c44515023 100644
> --- a/src/libcamera/pipeline/simple/simple.cpp
> +++ b/src/libcamera/pipeline/simple/simple.cpp
> @@ -314,8 +314,8 @@ int SimpleCameraData::init()
>  
>  			config.outputSizes = converter->sizes(format.size);
>  
> -			for (PixelFormat format : converter->formats(pixelFormat))
> -				formats_[format] = config;
> +			for (PixelFormat fmt : converter->formats(pixelFormat))
> +				formats_[fmt] = config;
>  		}
>  	}
>  
> diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> index 8ec0dac1e689..54ba1b87bb3e 100644
> --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> @@ -490,8 +490,8 @@ int UVCCameraData::init(MediaDevice *media)
>  	/* Locate and initialise the camera data with the default video node. */
>  	const std::vector<MediaEntity *> &entities = media->entities();
>  	auto entity = std::find_if(entities.begin(), entities.end(),
> -				   [](MediaEntity *entity) {
> -					   return entity->flags() & MEDIA_ENT_FL_DEFAULT;
> +				   [](MediaEntity *e) {
> +					   return e->flags() & MEDIA_ENT_FL_DEFAULT;
>  				   });
>  	if (entity == entities.end()) {
>  		LOG(UVC, Error) << "Could not find a default video device";

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
index 26dbd2573e04..85e0a1f26ab6 100644
--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
@@ -512,9 +512,9 @@  CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,
 		/* Translate the V4L2PixelFormat to PixelFormat. */
 		std::map<PixelFormat, std::vector<SizeRange>> deviceFormats;
 		for (const auto &format : fmts) {
-			PixelFormat pixelFormat = format.first.toPixelFormat();
-			if (pixelFormat.isValid())
-				deviceFormats[pixelFormat] = format.second;
+			PixelFormat pf = format.first.toPixelFormat();
+			if (pf.isValid())
+				deviceFormats[pf] = format.second;
 		}
 
 		/* Add the stream format based on the device node used for the use case. */
diff --git a/src/libcamera/pipeline/simple/converter.cpp b/src/libcamera/pipeline/simple/converter.cpp
index 75fb297ebd58..2b541cd2bb3f 100644
--- a/src/libcamera/pipeline/simple/converter.cpp
+++ b/src/libcamera/pipeline/simple/converter.cpp
@@ -72,11 +72,11 @@  std::vector<PixelFormat> SimpleConverter::formats(PixelFormat input)
 	 * Set the format on the input side (V4L2 output) of the converter to
 	 * enumerate the conversion capabilities on its output (V4L2 capture).
 	 */
-	V4L2DeviceFormat format;
-	format.fourcc = m2m_->output()->toV4L2PixelFormat(input);
-	format.size = { 1, 1 };
+	V4L2DeviceFormat v4l2Format;
+	v4l2Format.fourcc = m2m_->output()->toV4L2PixelFormat(input);
+	v4l2Format.size = { 1, 1 };
 
-	int ret = m2m_->output()->setFormat(&format);
+	int ret = m2m_->output()->setFormat(&v4l2Format);
 	if (ret < 0) {
 		LOG(SimplePipeline, Error)
 			<< "Failed to set format: " << strerror(-ret);
diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
index 7adb17e2d1db..999c44515023 100644
--- a/src/libcamera/pipeline/simple/simple.cpp
+++ b/src/libcamera/pipeline/simple/simple.cpp
@@ -314,8 +314,8 @@  int SimpleCameraData::init()
 
 			config.outputSizes = converter->sizes(format.size);
 
-			for (PixelFormat format : converter->formats(pixelFormat))
-				formats_[format] = config;
+			for (PixelFormat fmt : converter->formats(pixelFormat))
+				formats_[fmt] = config;
 		}
 	}
 
diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
index 8ec0dac1e689..54ba1b87bb3e 100644
--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
@@ -490,8 +490,8 @@  int UVCCameraData::init(MediaDevice *media)
 	/* Locate and initialise the camera data with the default video node. */
 	const std::vector<MediaEntity *> &entities = media->entities();
 	auto entity = std::find_if(entities.begin(), entities.end(),
-				   [](MediaEntity *entity) {
-					   return entity->flags() & MEDIA_ENT_FL_DEFAULT;
+				   [](MediaEntity *e) {
+					   return e->flags() & MEDIA_ENT_FL_DEFAULT;
 				   });
 	if (entity == entities.end()) {
 		LOG(UVC, Error) << "Could not find a default video device";