tests: Better handling of valgrind errors saving blobs

Currently we have 3 valgrind suppression files in the tests, all of which
are to handle memcheck errors that originate from saving entire buffers
containing blobs where the gaps between sub-blocks might not be
initialized.

We can more simply suppress those errors by having the save_blob() helper
use valgrind's client interface to mark the data as initialized before we
write it out.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Tested-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
David Gibson 2018-03-17 20:05:24 +11:00
parent e2556aaeb5
commit 5b67d2b955
4 changed files with 12 additions and 33 deletions

View File

@ -1,7 +0,0 @@
{
uninitialized alignment gaps can be dumped to output
Memcheck:Param
write(buf)
obj:/lib/ld-*.so
fun:main
}

View File

@ -1,7 +0,0 @@
{
opened blob dumps uninitialized data
Memcheck:Param
write(buf)
obj:/lib/ld-*.so
fun:main
}

View File

@ -1,18 +0,0 @@
{
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
fun:utilfdt_write_err
fun:save_blob
fun:main
}

View File

@ -30,6 +30,8 @@
#include <unistd.h>
#include <fcntl.h>
#include <valgrind/memcheck.h>
#include <libfdt.h>
#include "tests.h"
@ -179,11 +181,20 @@ void *load_blob_arg(int argc, char *argv[])
void save_blob(const char *filename, void *fdt)
{
int ret = utilfdt_write_err(filename, fdt);
size_t size = fdt_totalsize(fdt);
void *tmp;
int ret;
/* Make a temp copy of the blob so that valgrind won't check
* about uninitialized bits in the pieces between blocks */
tmp = xmalloc(size);
fdt_move(fdt, tmp, size);
VALGRIND_MAKE_MEM_DEFINED(tmp, size);
ret = utilfdt_write_err(filename, tmp);
if (ret)
CONFIG("Couldn't write blob to \"%s\": %s", filename,
strerror(ret));
free(tmp);
}
void *open_blob_rw(void *blob)