tpm: silence an array overflow warning
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 3 Feb 2017 10:30:40 +0000 (13:30 +0300)
committerJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Fri, 3 Feb 2017 20:33:55 +0000 (22:33 +0200)
We should check that we're within bounds first before checking that
"chip->active_banks[i] != TPM2_ALG_ERROR" so I've re-ordered the two
checks.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
drivers/char/tpm/tpm-interface.c

index 423938e8570f7fe296493d71def42ee1fcb11ee3..087748b8264fa7cb5b3e45e130fbb34d31634bc7 100644 (file)
@@ -800,8 +800,8 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash)
        if (chip->flags & TPM_CHIP_FLAG_TPM2) {
                memset(digest_list, 0, sizeof(digest_list));
 
-               for (i = 0; chip->active_banks[i] != TPM2_ALG_ERROR &&
-                    i < ARRAY_SIZE(chip->active_banks); i++) {
+               for (i = 0; i < ARRAY_SIZE(chip->active_banks) &&
+                           chip->active_banks[i] != TPM2_ALG_ERROR; i++) {
                        digest_list[i].alg_id = chip->active_banks[i];
                        memcpy(digest_list[i].digest, hash, TPM_DIGEST_SIZE);
                        count++;