diff options
author | Simon Glass <sjg@chromium.org> | 2018-06-12 09:04:59 +0300 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2018-06-19 14:31:44 +0300 |
commit | dd0ee9ea857c4e4d927ae41791c1626fd57c301d (patch) | |
tree | 231962584a8b572586605b81e42c3f9fa0ebc4ef | |
parent | e178db1d7736a92951fdc7f1fd9b8ecf4d2877ba (diff) | |
download | u-boot-dd0ee9ea857c4e4d927ae41791c1626fd57c301d.tar.xz |
fdtgrep: Separate out checking of two allocations
The current code might succeed on the first allocation and fail on the
second. Separate the checks to avoid this problem.
Of course, free() will never fail and the chances that (when allocating
two small areas) one will succeed and one will fail are just as remote.
But this keeps coverity happy.
Reported-by: Coverity (CID: 131226)
Signed-off-by: Simon Glass <sjg@chromium.org>
-rw-r--r-- | tools/fdtgrep.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/tools/fdtgrep.c b/tools/fdtgrep.c index 1f64fc38ff..8f44f599c1 100644 --- a/tools/fdtgrep.c +++ b/tools/fdtgrep.c @@ -133,11 +133,11 @@ static int value_add(struct display_info *disp, struct value_node **headp, } str = strdup(str); + if (!str) + goto err_mem; node = malloc(sizeof(*node)); - if (!str || !node) { - fprintf(stderr, "Out of memory\n"); - return -1; - } + if (!node) + goto err_mem; node->next = *headp; node->type = type; node->include = include; @@ -145,6 +145,9 @@ static int value_add(struct display_info *disp, struct value_node **headp, *headp = node; return 0; +err_mem: + fprintf(stderr, "Out of memory\n"); + return -1; } static bool util_is_printable_string(const void *data, int len) |