]> git.baikalelectronics.ru Git - arm-tf.git/commitdiff
fiptool: introduce xzalloc() helper function
authorMasahiro Yamada <yamada.masahiro@socionext.com>
Sat, 14 Jan 2017 15:50:41 +0000 (00:50 +0900)
committerMasahiro Yamada <yamada.masahiro@socionext.com>
Sat, 14 Jan 2017 16:07:20 +0000 (01:07 +0900)
We often want to zero out allocated memory.

My main motivation for this commit is to set image::next and
image_desc::next to NULL automatically in the next commit.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
tools/fiptool/fiptool.c

index fc0c8d6632c0bceb10dae2a4312f001f8bf3bb73..4b91b1f9fec0fd95ea39a5d9fc270674d881e66c 100644 (file)
@@ -155,12 +155,17 @@ static void *xmalloc(size_t size, const char *msg)
        return d;
 }
 
+static void *xzalloc(size_t size, const char *msg)
+{
+       return memset(xmalloc(size, msg), 0, size);
+}
+
 static image_desc_t *new_image_desc(const uuid_t *uuid,
     const char *name, const char *cmdline_name)
 {
        image_desc_t *desc;
 
-       desc = xmalloc(sizeof(*desc),
+       desc = xzalloc(sizeof(*desc),
            "failed to allocate memory for image descriptor");
        memcpy(&desc->uuid, uuid, sizeof(uuid_t));
        desc->name = xstrdup(name,
@@ -168,7 +173,6 @@ static image_desc_t *new_image_desc(const uuid_t *uuid,
        desc->cmdline_name = xstrdup(cmdline_name,
            "failed to allocate memory for image command line name");
        desc->action = DO_UNSPEC;
-       desc->action_arg = NULL;
        return desc;
 }