[Crosstoolchain-logs] [device-tree-compiler] 106/198: Fix valgrind errors in sw_tree1

Hector Oron zumbi at moszumanska.debian.org
Thu Dec 8 17:06:58 UTC 2016


This is an automated email from the git hooks/post-receive script.

zumbi pushed a commit to branch upstream/1.4.x
in repository device-tree-compiler.

commit a7ecdb4e751051a31ae8b40333d85c578ce8ea8d
Author: David Gibson <david at gibson.dropbear.id.au>
Date:   Tue Dec 31 22:34:05 2013 +1100

    Fix valgrind errors in sw_tree1
    
    The sw_tree1 testcase has accumulated some valgrind errors, at least in
    the "realloc" mode.
      * It had both a realloc_fdt() and explicit xmalloc() for the initial
    allocation which was redundant and caused errors.
      * It doesn't make sense to call fdt_resize() until after we've created
    the initial stub tree
      * Alignment gaps inserted into the tree contain uninitialized data, which
    trips an error when we write it out.  We could zero the buffer, but that
    would make it easier to miss real bugs, so we add suppressions for the
    valgrind warnings instead.
    
    Signed-off-by: David Gibson <david at gibson.dropbear.id.au>
---
 tests/sw_tree1.c    | 13 ++++++++-----
 tests/sw_tree1.supp | 18 ++++++++++++++++++
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/tests/sw_tree1.c b/tests/sw_tree1.c
index de00707..6d4c531 100644
--- a/tests/sw_tree1.c
+++ b/tests/sw_tree1.c
@@ -37,7 +37,7 @@ static enum {
 	REALLOC,
 } alloc_mode;
 
-static void realloc_fdt(void **fdt, size_t *size)
+static void realloc_fdt(void **fdt, size_t *size, bool created)
 {
 	switch (alloc_mode) {
 	case FIXED:
@@ -61,7 +61,8 @@ static void realloc_fdt(void **fdt, size_t *size)
 	case REALLOC:
 		*size += 1;
 		*fdt = xrealloc(*fdt, *size);
-		fdt_resize(*fdt, *fdt, *size);
+		if (created)
+			fdt_resize(*fdt, *fdt, *size);
 		return;
 
 	default:
@@ -73,7 +74,7 @@ static void realloc_fdt(void **fdt, size_t *size)
 	do {			      \
 		err = (code);			     \
 		if (err == -FDT_ERR_NOSPACE)			\
-			realloc_fdt(&fdt, &size);			\
+			realloc_fdt(&fdt, &size, created);		\
 		else if (err)						\
 			FAIL(#code ": %s", fdt_strerror(err));		\
 	} while (err != 0)
@@ -83,6 +84,7 @@ int main(int argc, char *argv[])
 	void *fdt = NULL;
 	size_t size;
 	int err;
+	bool created = false;
 
 	test_init(argc, argv);
 
@@ -108,12 +110,13 @@ int main(int argc, char *argv[])
 		}
 	}
 
-	realloc_fdt(&fdt, &size);
-	
 	fdt = xmalloc(size);
 	CHECK(fdt_create(fdt, size));
 
+	created = true;
+
 	CHECK(fdt_add_reservemap_entry(fdt, TEST_ADDR_1, TEST_SIZE_1));
+
 	CHECK(fdt_add_reservemap_entry(fdt, TEST_ADDR_2, TEST_SIZE_2));
 	CHECK(fdt_finish_reservemap(fdt));
 
diff --git a/tests/sw_tree1.supp b/tests/sw_tree1.supp
new file mode 100644
index 0000000..279f9e5
--- /dev/null
+++ b/tests/sw_tree1.supp
@@ -0,0 +1,18 @@
+{
+   allocation methods causes uninitialized data in alignment gap
+   Memcheck:Param
+   write(buf)
+   fun:__write_nocancel
+   fun:utilfdt_write_err
+   fun:save_blob
+   fun:main
+}
+{
+   allocation methods causes uninitialized data in alignment gap
+   Memcheck:Param
+   write(buf)
+   fun:__write_nocancel
+   fun:utilfdt_write_err
+   fun:save_blob
+   fun:main
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/crosstoolchain/device-tree-compiler.git



More information about the Crosstoolchain-logs mailing list