[libcamera-devel] libcamera: media_device: Zero media graph arrays when querying topology

Message ID 20190102113122.12751-1-laurent.pinchart@ideasonboard.com
State Accepted
Commit c59272f417e03e1a64d12296d66ba0004f0aa78c
Headers show
Series
  • [libcamera-devel] libcamera: media_device: Zero media graph arrays when querying topology
Related show

Commit Message

Laurent Pinchart Jan. 2, 2019, 11:31 a.m. UTC
This silences valgrind that otherwise warns about usage of uninitialized
values. While not strictly required as the kernel should fill the whole
arrays in MEDIA_IOC_G_TOPOLOGY, the extra cost, in a non-critical path,
is negligible compared to the ability to run without valgrind warnings.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/libcamera/media_device.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Jacopo Mondi Jan. 2, 2019, 11:39 a.m. UTC | #1
Hi Laurent,

On Wed, Jan 02, 2019 at 01:31:22PM +0200, Laurent Pinchart wrote:
> This silences valgrind that otherwise warns about usage of uninitialized
> values. While not strictly required as the kernel should fill the whole
> arrays in MEDIA_IOC_G_TOPOLOGY, the extra cost, in a non-critical path,
> is negligible compared to the ability to run without valgrind warnings.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  src/libcamera/media_device.cpp | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp
> index 4ff9ffe1041d..cc307dac1c33 100644
> --- a/src/libcamera/media_device.cpp
> +++ b/src/libcamera/media_device.cpp
> @@ -240,10 +240,10 @@ int MediaDevice::populate()
>  		delete[] pads;
>  		delete[] interfaces;
>
> -		ents = new media_v2_entity[topology.num_entities];
> -		links = new media_v2_link[topology.num_links];
> -		pads = new media_v2_pad[topology.num_pads];
> -		interfaces = new media_v2_interface[topology.num_interfaces];
> +		ents = new media_v2_entity[topology.num_entities]();
> +		links = new media_v2_link[topology.num_links]();
> +		pads = new media_v2_pad[topology.num_pads]();
> +		interfaces = new media_v2_interface[topology.num_interfaces]();

Ah ups, I dropped this from Niklas' code... It is worth if it silences
valgring warnings...

Please push
Thanks
  j

>
>  		version = topology.topology_version;
>  	}
> --
> Regards,
>
> Laurent Pinchart
>
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch

diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp
index 4ff9ffe1041d..cc307dac1c33 100644
--- a/src/libcamera/media_device.cpp
+++ b/src/libcamera/media_device.cpp
@@ -240,10 +240,10 @@  int MediaDevice::populate()
 		delete[] pads;
 		delete[] interfaces;
 
-		ents = new media_v2_entity[topology.num_entities];
-		links = new media_v2_link[topology.num_links];
-		pads = new media_v2_pad[topology.num_pads];
-		interfaces = new media_v2_interface[topology.num_interfaces];
+		ents = new media_v2_entity[topology.num_entities]();
+		links = new media_v2_link[topology.num_links]();
+		pads = new media_v2_pad[topology.num_pads]();
+		interfaces = new media_v2_interface[topology.num_interfaces]();
 
 		version = topology.topology_version;
 	}