Merge tag 'efi-2022-01-rc2-2' of https://source.denx.de/u-boot/custodians/u-boot-efi
[platform/kernel/u-boot.git] / board / freescale / common / fsl_validate.c
index 066aa9a..34875d0 100644 (file)
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright 2015 Freescale Semiconductor, Inc.
+ * Copyright 2021 NXP
  */
 
 #include <common.h>
@@ -500,7 +501,6 @@ static int calc_img_key_hash(struct fsl_secboot_img_priv *img)
        ret = algo->hash_init(algo, &ctx);
        if (ret)
                return ret;
-
        /* Update hash for ESBC key */
 #ifdef CONFIG_KEY_REVOCATION
        if (check_srk(img)) {
@@ -515,12 +515,12 @@ static int calc_img_key_hash(struct fsl_secboot_img_priv *img)
                        img->img_key, img->key_len, 1);
        if (ret)
                return ret;
-
        /* Copy hash at destination buffer */
        ret = algo->hash_finish(algo, ctx, hash_val, algo->digest_size);
-       if (ret)
+       if (ret) {
+               free(ctx);
                return ret;
-
+       }
        for (i = 0; i < SHA256_BYTES; i++)
                img->img_key_hash[i] = hash_val[i];
 
@@ -583,9 +583,10 @@ static int calc_esbchdr_esbc_hash(struct fsl_secboot_img_priv *img)
 #endif
        if (ret)
                return ret;
-       if (!key_hash)
+       if (!key_hash) {
+               free(ctx);
                return ERROR_KEY_TABLE_NOT_FOUND;
-
+       }
        /* Update hash for actual Image */
        ret = algo->hash_update(algo, ctx,
                (u8 *)(*(img->img_addr_ptr)), img->img_size, 1);
@@ -594,9 +595,10 @@ static int calc_esbchdr_esbc_hash(struct fsl_secboot_img_priv *img)
 
        /* Copy hash at destination buffer */
        ret = algo->hash_finish(algo, ctx, hash_val, algo->digest_size);
-       if (ret)
+       if (ret) {
+               free(ctx);
                return ret;
-
+       }
        return 0;
 }