diff mbox series

[v4,2/3] tpm_tis: assert valid addr passed to tpm_tis_locality_from_addr()

Message ID 1550236979-15658-2-git-send-email-liam.merwick@oracle.com (mailing list archive)
State New, archived
Headers show
Series rom c17b1cc4b07370e504cc0ca4ce4af560a83d5977 Mon Sep 17 00:00:00 2001 | expand

Commit Message

Liam Merwick Feb. 15, 2019, 1:22 p.m. UTC
Assert that the address passed in results in a valid locality value.
Current callers pass a valid address so this is just a defensive check
to prevent future caller passing an incorrect address or catch if the
MMIO address parameters were not all modified correctly.  This is to
help static code analysis tools that report that no explicit checking
is being done.

Signed-off-by: Liam Merwick <Liam.Merwick@oracle.com>
---
 hw/tpm/tpm_tis.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c
index 61a130beef35..772431f20874 100644
--- a/hw/tpm/tpm_tis.c
+++ b/hw/tpm/tpm_tis.c
@@ -100,7 +100,9 @@  static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr,
 
 static uint8_t tpm_tis_locality_from_addr(hwaddr addr)
 {
-    return (uint8_t)((addr >> TPM_TIS_LOCALITY_SHIFT) & 0x7);
+    uint8_t locty = (uint8_t)(addr >> TPM_TIS_LOCALITY_SHIFT);
+    assert(TPM_TIS_IS_VALID_LOCTY(locty));
+    return locty;
 }
 
 static void tpm_tis_show_buffer(const unsigned char *buffer,