]> Git Repo - u-boot.git/commitdiff
hash: fix a memory leak
authorSergei Antonov <[email protected]>
Mon, 12 Jun 2023 19:59:10 +0000 (22:59 +0300)
committerTom Rini <[email protected]>
Fri, 14 Jul 2023 19:21:07 +0000 (15:21 -0400)
memalign() returns a pointer which is to be freed by free(). To call
unmap_sysmem() is incorrect, furthermore it was called in a wrong scope.

Also add a check for allocation error.

Fixes: d7af2baa49c6 ("crypto/fsl: Fix HW accelerated hash commands")
Cc: Breno Lima <[email protected]>
Signed-off-by: Sergei Antonov <[email protected]>
Reviewed-by: Simon Glass <[email protected]>
common/hash.c

index 9a52d6073ceba0db382add14e286b01d95eb087f..cbffdfd6db36f2bebe6f3ba9b3f64d3f8efbe895 100644 (file)
@@ -586,6 +586,8 @@ int hash_command(const char *algo_name, int flags, struct cmd_tbl *cmdtp,
 
                output = memalign(ARCH_DMA_MINALIGN,
                                  sizeof(uint32_t) * HASH_MAX_DIGEST_SIZE);
+               if (!output)
+                       return CMD_RET_FAILURE;
 
                buf = map_sysmem(addr, len);
                algo->hash_func_ws(buf, len, output, algo->chunk_size);
@@ -602,6 +604,7 @@ int hash_command(const char *algo_name, int flags, struct cmd_tbl *cmdtp,
                                        flags & HASH_FLAG_ENV)) {
                                printf("ERROR: %s does not contain a valid "
                                        "%s sum\n", *argv, algo->name);
+                               free(output);
                                return 1;
                        }
                        if (memcmp(output, vsum, algo->digest_size) != 0) {
@@ -612,6 +615,7 @@ int hash_command(const char *algo_name, int flags, struct cmd_tbl *cmdtp,
                                for (i = 0; i < algo->digest_size; i++)
                                        printf("%02x", vsum[i]);
                                puts(" ** ERROR **\n");
+                               free(output);
                                return 1;
                        }
                } else {
@@ -622,10 +626,10 @@ int hash_command(const char *algo_name, int flags, struct cmd_tbl *cmdtp,
                                store_result(algo, output, *argv,
                                        flags & HASH_FLAG_ENV);
                        }
-               unmap_sysmem(output);
-
                }
 
+               free(output);
+
        /* Horrible code size hack for boards that just want crc32 */
        } else {
                ulong crc;
This page took 0.033096 seconds and 4 git commands to generate.