diff options
author | Liam Merwick <liam.merwick@oracle.com> | 2019-02-15 13:35:19 +0000 |
---|---|---|
committer | Stefan Berger <stefanb@linux.vnet.ibm.com> | 2019-02-24 14:46:14 -0500 |
commit | cd38cc519b60bbe5dd8d85f6aaa72b2d7902930b (patch) | |
tree | d2f280458b2d2173fff480d7944bffe5af8cd6ad /hw/tpm/tpm_tis.c | |
parent | 37b55d67c0f001b20b7831db3f9f24f1d453e1de (diff) |
tpm_tis: convert tpm_tis_show_buffer() to use trace event
cppcheck reports:
[hw/tpm/tpm_tis.c:113]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'
Rather than just converting the format specifier to use '%u", the
tpm_tis_show_buffer() function is converted to use trace points and
the two debug callers use the trace event infrastructure so that it's
available in production cases also and not just when DEBUG_TIS is enabled.
Signed-off-by: Liam Merwick <liam.merwick@oracle.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Diffstat (limited to 'hw/tpm/tpm_tis.c')
-rw-r--r-- | hw/tpm/tpm_tis.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 61a130beef..fd183e8deb 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -106,17 +106,26 @@ static uint8_t tpm_tis_locality_from_addr(hwaddr addr) static void tpm_tis_show_buffer(const unsigned char *buffer, size_t buffer_size, const char *string) { - uint32_t len, i; + size_t len, i; + char *line_buffer, *p; len = MIN(tpm_cmd_get_size(buffer), buffer_size); - printf("tpm_tis: %s length = %d\n", string, len); - for (i = 0; i < len; i++) { + + /* + * allocate enough room for 3 chars per buffer entry plus a + * newline after every 16 chars and a final null terminator. + */ + line_buffer = g_malloc(len * 3 + (len / 16) + 1); + + for (i = 0, p = line_buffer; i < len; i++) { if (i && !(i % 16)) { - printf("\n"); + p += sprintf(p, "\n"); } - printf("%.2X ", buffer[i]); + p += sprintf(p, "%.2X ", buffer[i]); } - printf("\n"); + trace_tpm_tis_show_buffer(string, len, line_buffer); + + g_free(line_buffer); } /* @@ -143,9 +152,8 @@ static void tpm_tis_sts_set(TPMLocality *l, uint32_t flags) */ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) { - if (DEBUG_TIS) { - tpm_tis_show_buffer(s->buffer, s->be_buffer_size, - "tpm_tis: To TPM"); + if (trace_event_get_state_backends(TRACE_TPM_TIS_SHOW_BUFFER)) { + tpm_tis_show_buffer(s->buffer, s->be_buffer_size, "To TPM"); } /* @@ -313,9 +321,8 @@ static void tpm_tis_request_completed(TPMIf *ti, int ret) s->loc[locty].state = TPM_TIS_STATE_COMPLETION; s->rw_offset = 0; - if (DEBUG_TIS) { - tpm_tis_show_buffer(s->buffer, s->be_buffer_size, - "tpm_tis: From TPM"); + if (trace_event_get_state_backends(TRACE_TPM_TIS_SHOW_BUFFER)) { + tpm_tis_show_buffer(s->buffer, s->be_buffer_size, "From TPM"); } if (TPM_TIS_IS_VALID_LOCTY(s->next_locty)) { |