Skip to content

Commit 2f25740

Browse files
author
Jarkko Sakkinen
committed
tpm: remove TPM_TRANSMIT_UNLOCKED flag
Added locking as part of tpm_try_get_ops() and tpm_put_ops() as they are anyway used in most of the call sites except in tpmrm_release() where we take the locks manually. Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Reviewed-by: Stefan Berger <stefanb@linux.ibm.com> Tested-by: Stefan Berger <stefanb@linux.ibm.com> Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com> Reviewed-by: James Bottomley <James.Bottomley@HansenPartnership.com> Tested-by: Alexander Steffen <Alexander.Steffen@infineon.com>
1 parent 2677ca9 commit 2f25740

File tree

6 files changed

+17
-38
lines changed

6 files changed

+17
-38
lines changed

drivers/char/tpm/tpm-chip.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ int tpm_try_get_ops(struct tpm_chip *chip)
5858
if (!chip->ops)
5959
goto out_lock;
6060

61+
mutex_lock(&chip->tpm_mutex);
6162
return 0;
6263
out_lock:
6364
up_read(&chip->ops_sem);
@@ -75,6 +76,7 @@ EXPORT_SYMBOL_GPL(tpm_try_get_ops);
7576
*/
7677
void tpm_put_ops(struct tpm_chip *chip)
7778
{
79+
mutex_unlock(&chip->tpm_mutex);
7880
up_read(&chip->ops_sem);
7981
put_device(&chip->dev);
8082
}

drivers/char/tpm/tpm-dev-common.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ static ssize_t tpm_dev_transmit(struct tpm_chip *chip, struct tpm_space *space,
3333
struct tpm_header *header = (void *)buf;
3434
ssize_t ret, len;
3535

36-
mutex_lock(&chip->tpm_mutex);
3736
ret = tpm2_prepare_space(chip, space, buf, bufsiz);
3837
/* If the command is not implemented by the TPM, synthesize a
3938
* response with a TPM2_RC_COMMAND_CODE return for user-space.
@@ -46,18 +45,16 @@ static ssize_t tpm_dev_transmit(struct tpm_chip *chip, struct tpm_space *space,
4645
ret = sizeof(*header);
4746
}
4847
if (ret)
49-
goto out_lock;
48+
goto out_rc;
5049

51-
len = tpm_transmit(chip, buf, bufsiz, TPM_TRANSMIT_UNLOCKED);
50+
len = tpm_transmit(chip, buf, bufsiz, 0);
5251
if (len < 0)
5352
ret = len;
5453

5554
if (!ret)
5655
ret = tpm2_commit_space(chip, space, buf, &len);
5756

58-
out_lock:
59-
mutex_unlock(&chip->tpm_mutex);
60-
57+
out_rc:
6158
return ret ? ret : len;
6259
}
6360

drivers/char/tpm/tpm-interface.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,6 @@ ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
236236
memcpy(save, buf, save_size);
237237

238238
for (;;) {
239-
if (!(flags & TPM_TRANSMIT_UNLOCKED) &&
240-
!(flags & TPM_TRANSMIT_NESTED))
241-
mutex_lock(&chip->tpm_mutex);
242-
243239
if (chip->ops->clk_enable != NULL)
244240
chip->ops->clk_enable(chip, true);
245241

@@ -266,10 +262,6 @@ ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
266262
if (chip->ops->clk_enable != NULL)
267263
chip->ops->clk_enable(chip, false);
268264

269-
if (!(flags & TPM_TRANSMIT_UNLOCKED) &&
270-
!(flags & TPM_TRANSMIT_NESTED))
271-
mutex_unlock(&chip->tpm_mutex);
272-
273265
if (ret < 0)
274266
break;
275267
rc = be32_to_cpu(header->return_code);

drivers/char/tpm/tpm.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,14 +488,10 @@ extern struct idr dev_nums_idr;
488488
/**
489489
* enum tpm_transmit_flags - flags for tpm_transmit()
490490
*
491-
* @TPM_TRANSMIT_UNLOCKED: do not lock the chip
492-
* @TPM_TRANSMIT_NESTED: discard setup steps (power management,
493-
* locality) including locking (i.e. implicit
494-
* UNLOCKED)
491+
* %TPM_TRANSMIT_NESTED: discard setup steps (power management, locality)
495492
*/
496493
enum tpm_transmit_flags {
497-
TPM_TRANSMIT_UNLOCKED = BIT(0),
498-
TPM_TRANSMIT_NESTED = BIT(1),
494+
TPM_TRANSMIT_NESTED = BIT(0),
499495
};
500496

501497
ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz,

drivers/char/tpm/tpm2-cmd.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -652,17 +652,12 @@ int tpm2_unseal_trusted(struct tpm_chip *chip,
652652
u32 blob_handle;
653653
int rc;
654654

655-
mutex_lock(&chip->tpm_mutex);
656-
rc = tpm2_load_cmd(chip, payload, options, &blob_handle,
657-
TPM_TRANSMIT_UNLOCKED);
655+
rc = tpm2_load_cmd(chip, payload, options, &blob_handle, 0);
658656
if (rc)
659-
goto out;
657+
return rc;
660658

661-
rc = tpm2_unseal_cmd(chip, payload, options, blob_handle,
662-
TPM_TRANSMIT_UNLOCKED);
663-
tpm2_flush_context_cmd(chip, blob_handle, TPM_TRANSMIT_UNLOCKED);
664-
out:
665-
mutex_unlock(&chip->tpm_mutex);
659+
rc = tpm2_unseal_cmd(chip, payload, options, blob_handle, 0);
660+
tpm2_flush_context_cmd(chip, blob_handle, 0);
666661
return rc;
667662
}
668663

drivers/char/tpm/tpm2-space.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ static void tpm2_flush_sessions(struct tpm_chip *chip, struct tpm_space *space)
3838

3939
for (i = 0; i < ARRAY_SIZE(space->session_tbl); i++) {
4040
if (space->session_tbl[i])
41-
tpm2_flush_context_cmd(chip, space->session_tbl[i],
42-
TPM_TRANSMIT_UNLOCKED);
41+
tpm2_flush_context_cmd(chip, space->session_tbl[i], 0);
4342
}
4443
}
4544

@@ -83,7 +82,7 @@ static int tpm2_load_context(struct tpm_chip *chip, u8 *buf,
8382
body_size = sizeof(*ctx) + be16_to_cpu(ctx->blob_size);
8483
tpm_buf_append(&tbuf, &buf[*offset], body_size);
8584

86-
rc = tpm_transmit_cmd(chip, &tbuf, 4, TPM_TRANSMIT_UNLOCKED, NULL);
85+
rc = tpm_transmit_cmd(chip, &tbuf, 4, 0, NULL);
8786
if (rc < 0) {
8887
dev_warn(&chip->dev, "%s: failed with a system error %d\n",
8988
__func__, rc);
@@ -131,7 +130,7 @@ static int tpm2_save_context(struct tpm_chip *chip, u32 handle, u8 *buf,
131130

132131
tpm_buf_append_u32(&tbuf, handle);
133132

134-
rc = tpm_transmit_cmd(chip, &tbuf, 0, TPM_TRANSMIT_UNLOCKED, NULL);
133+
rc = tpm_transmit_cmd(chip, &tbuf, 0, 0, NULL);
135134
if (rc < 0) {
136135
dev_warn(&chip->dev, "%s: failed with a system error %d\n",
137136
__func__, rc);
@@ -167,8 +166,7 @@ void tpm2_flush_space(struct tpm_chip *chip)
167166

168167
for (i = 0; i < ARRAY_SIZE(space->context_tbl); i++)
169168
if (space->context_tbl[i] && ~space->context_tbl[i])
170-
tpm2_flush_context_cmd(chip, space->context_tbl[i],
171-
TPM_TRANSMIT_UNLOCKED);
169+
tpm2_flush_context_cmd(chip, space->context_tbl[i], 0);
172170

173171
tpm2_flush_sessions(chip, space);
174172
}
@@ -416,7 +414,7 @@ static int tpm2_map_response_header(struct tpm_chip *chip, u32 cc, u8 *rsp,
416414

417415
return 0;
418416
out_no_slots:
419-
tpm2_flush_context_cmd(chip, phandle, TPM_TRANSMIT_UNLOCKED);
417+
tpm2_flush_context_cmd(chip, phandle, 0);
420418
dev_warn(&chip->dev, "%s: out of slots for 0x%08X\n", __func__,
421419
phandle);
422420
return -ENOMEM;
@@ -503,8 +501,7 @@ static int tpm2_save_space(struct tpm_chip *chip)
503501
} else if (rc)
504502
return rc;
505503

506-
tpm2_flush_context_cmd(chip, space->context_tbl[i],
507-
TPM_TRANSMIT_UNLOCKED);
504+
tpm2_flush_context_cmd(chip, space->context_tbl[i], 0);
508505
space->context_tbl[i] = ~0;
509506
}
510507

0 commit comments

Comments
 (0)