Skip to content

Commit 09b71a5

Browse files
committed
KEYS: trusted: Use tpm_ret_to_err() in trusted_tpm2
Use tpm_ret_to_err() to transmute TPM return codes in trusted_tpm2. Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@opinsys.com> Acked-by: Stefano Garzarella <sgarzare@redhat.com> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
1 parent 7fcf459 commit 09b71a5

1 file changed

Lines changed: 7 additions & 19 deletions

File tree

security/keys/trusted-keys/trusted_tpm2.c

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -333,25 +333,19 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
333333
}
334334

335335
blob_len = tpm2_key_encode(payload, options, &buf.data[offset], blob_len);
336+
if (blob_len < 0)
337+
rc = blob_len;
336338

337339
out:
338340
tpm_buf_destroy(&sized);
339341
tpm_buf_destroy(&buf);
340342

341-
if (rc > 0) {
342-
if (tpm2_rc_value(rc) == TPM2_RC_HASH)
343-
rc = -EINVAL;
344-
else
345-
rc = -EPERM;
346-
}
347-
if (blob_len < 0)
348-
rc = blob_len;
349-
else
343+
if (!rc)
350344
payload->blob_len = blob_len;
351345

352346
out_put:
353347
tpm_put_ops(chip);
354-
return rc;
348+
return tpm_ret_to_err(rc);
355349
}
356350

357351
/**
@@ -455,10 +449,7 @@ static int tpm2_load_cmd(struct tpm_chip *chip,
455449
out:
456450
tpm_buf_destroy(&buf);
457451

458-
if (rc > 0)
459-
rc = -EPERM;
460-
461-
return rc;
452+
return tpm_ret_to_err(rc);
462453
}
463454

464455
/**
@@ -521,8 +512,6 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip,
521512
tpm_buf_fill_hmac_session(chip, &buf);
522513
rc = tpm_transmit_cmd(chip, &buf, 6, "unsealing");
523514
rc = tpm_buf_check_hmac_response(chip, &buf, rc);
524-
if (rc > 0)
525-
rc = -EPERM;
526515

527516
if (!rc) {
528517
data_len = be16_to_cpup(
@@ -555,7 +544,7 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip,
555544

556545
out:
557546
tpm_buf_destroy(&buf);
558-
return rc;
547+
return tpm_ret_to_err(rc);
559548
}
560549

561550
/**
@@ -587,6 +576,5 @@ int tpm2_unseal_trusted(struct tpm_chip *chip,
587576

588577
out:
589578
tpm_put_ops(chip);
590-
591-
return rc;
579+
return tpm_ret_to_err(rc);
592580
}

0 commit comments

Comments
 (0)