All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Stefan Berger <stefanb@linux.vnet.ibm.com>, qemu-trivial@nongnu.org
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH] tpm_tis: fix format for 64bit variable
Date: Tue, 31 Mar 2015 08:15:01 -0600	[thread overview]
Message-ID: <551AABE5.1020509@redhat.com> (raw)
In-Reply-To: <551AAA82.9090608@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1860 bytes --]

On 03/31/2015 08:09 AM, Eric Blake wrote:
> On 03/31/2015 07:27 AM, Stefan Berger wrote:
>> Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
>> ---
>>  hw/tpm/tpm_tis.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c
>> index 815c8ea..52e0148 100644
>> --- a/hw/tpm/tpm_tis.c
>> +++ b/hw/tpm/tpm_tis.c
>> @@ -814,7 +814,7 @@ static void tpm_tis_mmio_write_intern(void *opaque, hwaddr addr,
>>              tis->loc[locty].state == TPM_TIS_STATE_COMPLETION) {
>>              /* drop the byte */
>>          } else {
>> -            DPRINTF("tpm_tis: Data to send to TPM: %08x (size=%d)\n",
>> +            DPRINTF("tpm_tis: Data to send to TPM: %08lx (size=%d)\n",
> 
> NACK.  When printing uint64_t val, you HAVE to use PRIx64, not lx, for
> the sake of 32-bit platforms.

Furthermore, you could have caught this much sooner if you fix the
definition of DPRINTF.  This file used:

#ifdef DEBUG_TIS
#define DPRINTF(fmt, ...) \
    do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
#else
#define DPRINTF(fmt, ...) \
    do { } while (0)
#endif

which is bad, because the compiler CAN'T see the type mismatch unless
you turn debugging on (alas, we have a LOT of files in the code base
with similar bad patterns).  A better example is hw/display/cg3.c:

/* Change to 1 to enable debugging */
#define DEBUG_CG3 0
...
#define DPRINTF(fmt, ...) do { \
    if (DEBUG_CG3) { \
        printf("CG3: " fmt , ## __VA_ARGS__); \
    } \
} while (0);

where now the compiler can unconditionally do -Wformat checking and
avoid bit-rot, even if debug printing is never turned on, and without
penalizing code size when debugging is off.


-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: Eric Blake <eblake@redhat.com>
To: Stefan Berger <stefanb@linux.vnet.ibm.com>, qemu-trivial@nongnu.org
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] tpm_tis: fix format for 64bit variable
Date: Tue, 31 Mar 2015 08:15:01 -0600	[thread overview]
Message-ID: <551AABE5.1020509@redhat.com> (raw)
In-Reply-To: <551AAA82.9090608@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1860 bytes --]

On 03/31/2015 08:09 AM, Eric Blake wrote:
> On 03/31/2015 07:27 AM, Stefan Berger wrote:
>> Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
>> ---
>>  hw/tpm/tpm_tis.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c
>> index 815c8ea..52e0148 100644
>> --- a/hw/tpm/tpm_tis.c
>> +++ b/hw/tpm/tpm_tis.c
>> @@ -814,7 +814,7 @@ static void tpm_tis_mmio_write_intern(void *opaque, hwaddr addr,
>>              tis->loc[locty].state == TPM_TIS_STATE_COMPLETION) {
>>              /* drop the byte */
>>          } else {
>> -            DPRINTF("tpm_tis: Data to send to TPM: %08x (size=%d)\n",
>> +            DPRINTF("tpm_tis: Data to send to TPM: %08lx (size=%d)\n",
> 
> NACK.  When printing uint64_t val, you HAVE to use PRIx64, not lx, for
> the sake of 32-bit platforms.

Furthermore, you could have caught this much sooner if you fix the
definition of DPRINTF.  This file used:

#ifdef DEBUG_TIS
#define DPRINTF(fmt, ...) \
    do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
#else
#define DPRINTF(fmt, ...) \
    do { } while (0)
#endif

which is bad, because the compiler CAN'T see the type mismatch unless
you turn debugging on (alas, we have a LOT of files in the code base
with similar bad patterns).  A better example is hw/display/cg3.c:

/* Change to 1 to enable debugging */
#define DEBUG_CG3 0
...
#define DPRINTF(fmt, ...) do { \
    if (DEBUG_CG3) { \
        printf("CG3: " fmt , ## __VA_ARGS__); \
    } \
} while (0);

where now the compiler can unconditionally do -Wformat checking and
avoid bit-rot, even if debug printing is never turned on, and without
penalizing code size when debugging is off.


-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2015-03-31 14:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-31 13:27 [Qemu-trivial] [PATCH] tpm_tis: fix format for 64bit variable Stefan Berger
2015-03-31 13:27 ` [Qemu-devel] " Stefan Berger
2015-03-31 14:09 ` [Qemu-trivial] " Eric Blake
2015-03-31 14:09   ` Eric Blake
2015-03-31 14:15   ` Eric Blake [this message]
2015-03-31 14:15     ` Eric Blake
2015-03-31 15:35     ` [Qemu-trivial] " Stefan Berger
2015-03-31 15:35       ` Stefan Berger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=551AABE5.1020509@redhat.com \
    --to=eblake@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=stefanb@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.