ACK: [PATCH] tpmevlog: clean up some minor cppcheck style warnings
Alex Hung
alex.hung at canonical.com
Thu Jan 14 19:59:10 UTC 2021
On 2021-01-14 7:51 a.m., Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> Reduce teh scope of some variables and only initialize them
> when really required. Cleans up the following cppcheck style
> warnings:
>
> src/tpm/tpmevlog/tpmevlog.c:156:11: style: The scope of the variable
> 'event_size' can be reduced. [variableScope]
> uint32_t event_size = 0;
>
> src/tpm/tpmevlog/tpmevlog.c:442:13: style: The scope of the variable
> 'data' can be reduced. [variableScope]
> uint8_t *data;
>
> src/tpm/tpmevlog/tpmevlog.c:155:20: style: Variable 'hash_size' is
> assigned a value that is never used. [unreadVariable]
> uint8_t hash_size = 0;
>
> src/tpm/tpmevlog/tpmevlog.c:156:22: style: Variable 'event_size' is
> assigned a value that is never used. [unreadVariable]
> uint32_t event_size = 0;
>
> src/tpm/tpmevlog/tpmevlog.c:340:10: style: Variable 'ret' is assigned a
> value that is never used. [unreadVariable]
> int ret = FWTS_OK;
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
> src/tpm/tpmevlog/tpmevlog.c | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/src/tpm/tpmevlog/tpmevlog.c b/src/tpm/tpmevlog/tpmevlog.c
> index d712e131..1b952820 100644
> --- a/src/tpm/tpmevlog/tpmevlog.c
> +++ b/src/tpm/tpmevlog/tpmevlog.c
> @@ -152,8 +152,6 @@ static int tpmevlog_v2_check(fwts_framework *fw, uint8_t *data, size_t len)
> uint8_t *pdata = data;
> int i = 0;
> uint8_t vendor_info_size = 0;
> - uint8_t hash_size = 0;
> - uint32_t event_size = 0;
>
> /* specid_event_check */
> if (len < sizeof(fwts_pc_client_pcr_event)) {
> @@ -270,6 +268,8 @@ static int tpmevlog_v2_check(fwts_framework *fw, uint8_t *data, size_t len)
>
> /* Check the Crypto agile log format event */
> while (len_remain > 0) {
> + uint32_t event_size;
> +
> if (len_remain < sizeof(fwts_tcg_pcr_event2)) {
> fwts_failed(fw, LOG_LEVEL_MEDIUM, "EventV2Length",
> "The length of the event2 is %zd bytes "
> @@ -290,8 +290,8 @@ static int tpmevlog_v2_check(fwts_framework *fw, uint8_t *data, size_t len)
> pdata += sizeof(fwts_tcg_pcr_event2);
> len_remain -= sizeof(fwts_tcg_pcr_event2);
> for (i = 0; i < pcr_event2->digests_count; i++) {
> + uint8_t hash_size;
>
> - hash_size = 0;
> TPM2_ALG_ID alg_id = *(TPM2_ALG_ID *)pdata;
>
> ret = tpmevlog_algid_check(fw, alg_id);
> @@ -337,10 +337,11 @@ static int tpmevlog_check(fwts_framework *fw, uint8_t *data, size_t len)
> {
>
> uint8_t *pdata = data;
> - int ret = FWTS_OK;
> fwts_pc_client_pcr_event *pc_event = NULL;
>
> do {
> + int ret;
> +
> if (len < sizeof(fwts_pc_client_pcr_event)) {
> fwts_failed(fw, LOG_LEVEL_MEDIUM, "EventLength",
> "The length of the event is %zd bytes "
> @@ -439,7 +440,6 @@ static int tpmevlog_test1(fwts_framework *fw)
> tpmdir = readdir(dir);
> if (tpmdir && strstr(tpmdir->d_name, "tpm")) {
> char path[PATH_MAX];
> - uint8_t *data;
> int fd;
> size_t length;
>
> @@ -449,6 +449,8 @@ static int tpmevlog_test1(fwts_framework *fw)
> snprintf(path, sizeof(path), FWTS_TPM_LOG_DIR_PATH "/%s/binary_bios_measurements", tpmdir->d_name);
>
> if ((fd = open(path, O_RDONLY)) >= 0) {
> + uint8_t *data;
> +
> data = tpmevlog_load_file(fd, &length);
> tpm_logfile_found = true;
> if (data == NULL) {
>
Acked-by: Alex Hung <alex.hung at canonical.com>
More information about the fwts-devel
mailing list