qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH for-1.6?] tpm.c: Don't try to put -1 in a variable of type TpmModel
@ 2013-07-29 11:22 Peter Maydell
  2013-07-29 20:23 ` Anthony Liguori
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Maydell @ 2013-07-29 11:22 UTC (permalink / raw)
  To: qemu-devel; +Cc: Anthony Liguori, Stefan Berger, patches

The TpmModel type is an enum (valid values 0 and 1), which means
the compiler can legitimately decide that comparisons like
'tpm_models[i] == -1' are never true. (For example it could
pick 'unsigned char' as its type for representing the enum.)

Avoid this issue by using TPM_MODEL_MAX to mark entries in
the tpm_models[] array which aren't filled in, instead of -1.

This silences a clang warning:

 tpm.c:43:27: error: comparison of constant -1 with expression of type
      'enum TpmModel' is always false [-Werror,-Wtautological-constant-out-of-range-compare]
        if (tpm_models[i] == -1) {
            ~~~~~~~~~~~~~ ^  ~~

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
Disclaimer: I have compiled this, and it's a pretty safe looking
change, but I haven't tested it...

 tpm.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tpm.c b/tpm.c
index f13c9bc..d68d69f 100644
--- a/tpm.c
+++ b/tpm.c
@@ -32,7 +32,7 @@ static TPMDriverOps const *be_drivers[TPM_MAX_DRIVERS] = {
 };
 
 static enum TpmModel tpm_models[TPM_MAX_MODELS] = {
-    -1,
+    TPM_MODEL_MAX,
 };
 
 int tpm_register_model(enum TpmModel model)
@@ -40,7 +40,7 @@ int tpm_register_model(enum TpmModel model)
     int i;
 
     for (i = 0; i < TPM_MAX_MODELS; i++) {
-        if (tpm_models[i] == -1) {
+        if (tpm_models[i] == TPM_MODEL_MAX) {
             tpm_models[i] = model;
             return 0;
         }
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH for-1.6?] tpm.c: Don't try to put -1 in a variable of type TpmModel
  2013-07-29 11:22 [Qemu-devel] [PATCH for-1.6?] tpm.c: Don't try to put -1 in a variable of type TpmModel Peter Maydell
@ 2013-07-29 20:23 ` Anthony Liguori
  0 siblings, 0 replies; 2+ messages in thread
From: Anthony Liguori @ 2013-07-29 20:23 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel; +Cc: Anthony Liguori, patches, Stefan Berger

Applied.  Thanks.

Regards,

Anthony Liguori

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-07-29 20:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-29 11:22 [Qemu-devel] [PATCH for-1.6?] tpm.c: Don't try to put -1 in a variable of type TpmModel Peter Maydell
2013-07-29 20:23 ` Anthony Liguori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).