Skip to content

Commit c4df71d

Browse files
author
Jarkko Sakkinen
committed
tpm: encapsulate tpm_dev_transmit()
Encapsulate tpm_transmit() call pattern to tpm_dev_transmit() because it is identically used from two places. Use unlocked version of tpm_transmit() so that we are able to move the calls to tpm2_prepare_space() and tpm2_commit_space() later on to this new function. 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 720b071 commit c4df71d

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,28 @@
2727
static struct workqueue_struct *tpm_dev_wq;
2828
static DEFINE_MUTEX(tpm_dev_wq_lock);
2929

30-
static void tpm_async_work(struct work_struct *work)
30+
static ssize_t tpm_dev_transmit(struct tpm_chip *chip, struct tpm_space *space,
31+
u8 *buf, size_t bufsiz)
32+
{
33+
ssize_t ret;
34+
35+
mutex_lock(&chip->tpm_mutex);
36+
ret = tpm_transmit(chip, space, buf, bufsiz, TPM_TRANSMIT_UNLOCKED);
37+
mutex_unlock(&chip->tpm_mutex);
38+
39+
return ret;
40+
}
41+
42+
static void tpm_dev_async_work(struct work_struct *work)
3143
{
3244
struct file_priv *priv =
3345
container_of(work, struct file_priv, async_work);
3446
ssize_t ret;
3547

3648
mutex_lock(&priv->buffer_mutex);
3749
priv->command_enqueued = false;
38-
ret = tpm_transmit(priv->chip, priv->space, priv->data_buffer,
39-
sizeof(priv->data_buffer), 0);
40-
50+
ret = tpm_dev_transmit(priv->chip, priv->space, priv->data_buffer,
51+
sizeof(priv->data_buffer));
4152
tpm_put_ops(priv->chip);
4253
if (ret > 0) {
4354
priv->response_length = ret;
@@ -80,7 +91,7 @@ void tpm_common_open(struct file *file, struct tpm_chip *chip,
8091
mutex_init(&priv->buffer_mutex);
8192
timer_setup(&priv->user_read_timer, user_reader_timeout, 0);
8293
INIT_WORK(&priv->timeout_work, tpm_timeout_work);
83-
INIT_WORK(&priv->async_work, tpm_async_work);
94+
INIT_WORK(&priv->async_work, tpm_dev_async_work);
8495
init_waitqueue_head(&priv->async_wait);
8596
file->private_data = priv;
8697
}
@@ -183,8 +194,8 @@ ssize_t tpm_common_write(struct file *file, const char __user *buf,
183194
return size;
184195
}
185196

186-
ret = tpm_transmit(priv->chip, priv->space, priv->data_buffer,
187-
sizeof(priv->data_buffer), 0);
197+
ret = tpm_dev_transmit(priv->chip, priv->space, priv->data_buffer,
198+
sizeof(priv->data_buffer));
188199
tpm_put_ops(priv->chip);
189200

190201
if (ret > 0) {

0 commit comments

Comments
 (0)