diff options
author | David Vincze <david.vincze@arm.com> | 2020-02-10 20:04:40 +0100 |
---|---|---|
committer | Tamas Ban <tamas.ban@arm.com> | 2020-03-11 10:00:33 +0000 |
commit | 062336b588f32da53d2cdd1bcec89bbca5fd8f61 (patch) | |
tree | cea01654ae569a541c47f161713f1651aeee5290 /bl2 | |
parent | 7f92a739d6e05cbd79bbd3f4b4cce1489bb0c022 (diff) | |
download | trusted-firmware-m-062336b588f32da53d2cdd1bcec89bbca5fd8f61.tar.gz |
Boot: Remove unnecessary loop
The TLV iterator can find the first required TLV in the image manifest.
Since there is only one security counter TLV there is no need to
continue the search and the surrounding loop can be removed.
Change-Id: I2ce04291537e853036b880cfe650c3bb8aa3e846
Signed-off-by: David Vincze <david.vincze@arm.com>
Diffstat (limited to 'bl2')
-rw-r--r-- | bl2/ext/mcuboot/bootutil/src/image_validate.c | 37 |
1 files changed, 13 insertions, 24 deletions
diff --git a/bl2/ext/mcuboot/bootutil/src/image_validate.c b/bl2/ext/mcuboot/bootutil/src/image_validate.c index 18dd3e1c6f..db9d5410a6 100644 --- a/bl2/ext/mcuboot/bootutil/src/image_validate.c +++ b/bl2/ext/mcuboot/bootutil/src/image_validate.c @@ -21,7 +21,7 @@ * Original code taken from mcuboot project at: * https://github.com/JuulLabs-OSS/mcuboot * Git SHA of the original version: ac55554059147fff718015be9f4bd3108123f50a - * Modifications are Copyright (c) 2018-2019 Arm Limited. + * Modifications are Copyright (c) 2018-2020 Arm Limited. */ #include <assert.h> @@ -193,7 +193,6 @@ bootutil_get_img_security_cnt(struct image_header *hdr, struct image_tlv_iter it; uint32_t off; uint16_t len; - uint32_t found = 0; int32_t rc; if ((hdr == NULL) || @@ -216,34 +215,24 @@ bootutil_get_img_security_cnt(struct image_header *hdr, /* Traverse through the protected TLV area to find * the security counter TLV. */ - while (true) { - rc = bootutil_tlv_iter_next(&it, &off, &len, NULL); - if (rc < 0) { - return -1; - } else if (rc > 0) { - break; - } - - if (len != sizeof(*img_security_cnt)) { - /* Security counter is not valid. */ - return BOOT_EBADIMAGE; - } - rc = LOAD_IMAGE_DATA(hdr, fap, off, img_security_cnt, len); - if (rc != 0) { - return BOOT_EFLASH; - } + rc = bootutil_tlv_iter_next(&it, &off, &len, NULL); + if (rc != 0) { + /* Security counter TLV has not been found. */ + return -1; + } - /* Security counter has been found. */ - found = 1; - break; + if (len != sizeof(*img_security_cnt)) { + /* Security counter is not valid. */ + return BOOT_EBADIMAGE; } - if (found) { - return 0; + rc = LOAD_IMAGE_DATA(hdr, fap, off, img_security_cnt, len); + if (rc != 0) { + return BOOT_EFLASH; } - return -1; + return 0; } /* |