[Skiboot] [PATCH 3/4] libstb: endian annotations
Nicholas Piggin
npiggin at gmail.com
Sun Nov 10 23:56:36 AEDT 2024
Add endian annotations to silence sparse endian warnings in libstb.
Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
---
libstb/secvar/storage/secboot_tpm.c | 8 ++++----
libstb/tss2/ibmtpm20tss/utils/tssauth20.c | 4 ++--
libstb/tss2/ibmtpm20tss/utils/tssdevskiboot.c | 4 ++--
libstb/tss2/ibmtpm20tss/utils/tssutils.c | 2 +-
4 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/libstb/secvar/storage/secboot_tpm.c b/libstb/secvar/storage/secboot_tpm.c
index ff8ea9e0a..1dce0c711 100644
--- a/libstb/secvar/storage/secboot_tpm.c
+++ b/libstb/secvar/storage/secboot_tpm.c
@@ -160,9 +160,9 @@ static char *secboot_serialize_secvar(char *target, const struct secvar *var, co
+ var->key_len + var->data_size) > end)
return NULL;
- *((uint64_t*) target) = cpu_to_be64(var->key_len);
+ *((beint64_t*) target) = cpu_to_be64(var->key_len);
target += sizeof(var->key_len);
- *((uint64_t*) target) = cpu_to_be64(var->data_size);
+ *((beint64_t*) target) = cpu_to_be64(var->data_size);
target += sizeof(var->data_size);
memcpy(target, var->key, var->key_len);
target += var->key_len;
@@ -289,9 +289,9 @@ static int secboot_deserialize_secvar(struct secvar **var, char **src, const cha
assert(var);
/* Load in the two header values */
- key_len = be64_to_cpu(*((uint64_t *) *src));
+ key_len = be64_to_cpu(*((beint64_t *) *src));
*src += sizeof(uint64_t);
- data_size = be64_to_cpu(*((uint64_t *) *src));
+ data_size = be64_to_cpu(*((beint64_t *) *src));
*src += sizeof(uint64_t);
/* Check if we've reached the last var to deserialize */
diff --git a/libstb/tss2/ibmtpm20tss/utils/tssauth20.c b/libstb/tss2/ibmtpm20tss/utils/tssauth20.c
index 8489e86d5..a3dafb9d4 100644
--- a/libstb/tss2/ibmtpm20tss/utils/tssauth20.c
+++ b/libstb/tss2/ibmtpm20tss/utils/tssauth20.c
@@ -1295,7 +1295,7 @@ TPM_RC TSS_GetCommandDecryptParam(TSS_AUTH_CONTEXT *tssAuthContext,
}
/* extract contents of the first TPM2B */
if (rc == 0) {
- *decryptParamSize = ntohs(*(uint16_t *)cpBuffer);
+ *decryptParamSize = ntohs(*(beint16_t *)cpBuffer);
*decryptParamBuffer = cpBuffer + sizeof(uint16_t);
}
/* sanity range check */
@@ -1491,7 +1491,7 @@ TPM_RC TSS_GetResponseEncryptParam(TSS_AUTH_CONTEXT *tssAuthContext,
}
/* extract contents of the first TPM2B */
if (rc == 0) {
- *encryptParamSize = ntohs(*(uint16_t *)rpBuffer);
+ *encryptParamSize = ntohs(*(beint16_t *)rpBuffer);
*encryptParamBuffer = rpBuffer + sizeof(uint16_t);
}
/* sanity range check */
diff --git a/libstb/tss2/ibmtpm20tss/utils/tssdevskiboot.c b/libstb/tss2/ibmtpm20tss/utils/tssdevskiboot.c
index 24d437985..e4b1b1072 100644
--- a/libstb/tss2/ibmtpm20tss/utils/tssdevskiboot.c
+++ b/libstb/tss2/ibmtpm20tss/utils/tssdevskiboot.c
@@ -166,7 +166,7 @@ TPM_RC TSS_Dev_Transmit(TSS_CONTEXT *tssContext,
* it here.
*/
if (rc == 0) {
- responseSize = ntohl(*(uint32_t *)(responseBuffer + sizeof(TPM_ST)));
+ responseSize = ntohl(*(beint32_t *)(responseBuffer + sizeof(TPM_ST)));
if (responseSize != *length) {
if (tssVerbose)
printf("TSS_Skiboot_Transmit: Bytes read (%u) and Buffer responseSize field (%lu) don't match\n",
@@ -180,7 +180,7 @@ TPM_RC TSS_Dev_Transmit(TSS_CONTEXT *tssContext,
* and deliver it to the upper layers
*/
if (rc == 0)
- rc = ntohl(*(uint32_t *)(responseBuffer + sizeof(TPM_ST) + sizeof(uint32_t)));
+ rc = ntohl(*(beint32_t *)(responseBuffer + sizeof(TPM_ST) + sizeof(uint32_t)));
if (tssVverbose)
printf("TSS_Skiboot_Transmit: Response Code: %08x", rc);
diff --git a/libstb/tss2/ibmtpm20tss/utils/tssutils.c b/libstb/tss2/ibmtpm20tss/utils/tssutils.c
index 29124c36e..90c4f568d 100644
--- a/libstb/tss2/ibmtpm20tss/utils/tssutils.c
+++ b/libstb/tss2/ibmtpm20tss/utils/tssutils.c
@@ -253,7 +253,7 @@ TPM_RC TSS_TPM2B_CreateUint32(TPM2B *target, uint32_t source, uint16_t targetSiz
}
}
if (rc == 0) {
- uint32_t sourceNbo = htonl(source);
+ beint32_t sourceNbo = htonl(source);
memmove(target->buffer, (uint8_t *)&sourceNbo, sizeof(uint32_t));
target->size = sizeof(uint32_t);
}
--
2.45.2
More information about the Skiboot
mailing list