From 559147c410310c9e7c0292ae6783b02ae466b3dd Mon Sep 17 00:00:00 2001 From: Paul Adelsbach Date: Wed, 4 Mar 2026 13:44:51 -0800 Subject: [PATCH] Add error returns in TPM2_IoCb_Zephyr_I2C --- hal/tpm_io_zephyr.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/hal/tpm_io_zephyr.c b/hal/tpm_io_zephyr.c index 4fffc860..97090c5c 100644 --- a/hal/tpm_io_zephyr.c +++ b/hal/tpm_io_zephyr.c @@ -94,6 +94,7 @@ int TPM2_IoCb_Zephyr_I2C(TPM2_CTX* ctx, int isRead, word32 addr, { int ret = 0; byte* tempBuf = NULL; + (void)userCtx; if (buf == NULL) { printf("Buffer passed is NULL"); @@ -111,11 +112,6 @@ int TPM2_IoCb_Zephyr_I2C(TPM2_CTX* ctx, int isRead, word32 addr, return -1; } - if (userCtx == NULL) { - //printf("UserCtx Cannot be NULL\n"); - } - - /* Init Zephyr I2C Driver */ if (_is_initialized_i2c == 0) { if (TPM2_I2C_Zephyr_Init() != 0) { @@ -129,6 +125,7 @@ int TPM2_IoCb_Zephyr_I2C(TPM2_CTX* ctx, int isRead, word32 addr, tempBuf = (byte*)XMALLOC(1, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (tempBuf == NULL) { printf("Failed to allocate temp buffer\n"); + return -1; } tempBuf[0] = (byte)(addr & 0xFF); @@ -143,10 +140,10 @@ int TPM2_IoCb_Zephyr_I2C(TPM2_CTX* ctx, int isRead, word32 addr, } else { // Write operation: Register address + Data - tempBuf = (byte*)XMALLOC(size + 1, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (tempBuf == NULL) { printf("Failed to allocate temp buffer\n"); + return -1; } tempBuf[0] = (byte)(addr & 0xFF); @@ -167,8 +164,6 @@ int TPM2_IoCb_Zephyr_I2C(TPM2_CTX* ctx, int isRead, word32 addr, } } - - (void)ctx; return ret; }