diff options
Diffstat (limited to 'drivers/char/tpm/tpm.c')
-rw-r--r-- | drivers/char/tpm/tpm.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c index ef991cd8c024..9bb542913b86 100644 --- a/drivers/char/tpm/tpm.c +++ b/drivers/char/tpm/tpm.c | |||
@@ -24,7 +24,9 @@ | |||
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include <linux/poll.h> | 26 | #include <linux/poll.h> |
27 | #include <linux/mutex.h> | ||
27 | #include <linux/spinlock.h> | 28 | #include <linux/spinlock.h> |
29 | |||
28 | #include "tpm.h" | 30 | #include "tpm.h" |
29 | 31 | ||
30 | enum tpm_const { | 32 | enum tpm_const { |
@@ -328,10 +330,10 @@ static void timeout_work(struct work_struct *work) | |||
328 | { | 330 | { |
329 | struct tpm_chip *chip = container_of(work, struct tpm_chip, work); | 331 | struct tpm_chip *chip = container_of(work, struct tpm_chip, work); |
330 | 332 | ||
331 | down(&chip->buffer_mutex); | 333 | mutex_lock(&chip->buffer_mutex); |
332 | atomic_set(&chip->data_pending, 0); | 334 | atomic_set(&chip->data_pending, 0); |
333 | memset(chip->data_buffer, 0, TPM_BUFSIZE); | 335 | memset(chip->data_buffer, 0, TPM_BUFSIZE); |
334 | up(&chip->buffer_mutex); | 336 | mutex_unlock(&chip->buffer_mutex); |
335 | } | 337 | } |
336 | 338 | ||
337 | /* | 339 | /* |
@@ -380,7 +382,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, | |||
380 | return -E2BIG; | 382 | return -E2BIG; |
381 | } | 383 | } |
382 | 384 | ||
383 | down(&chip->tpm_mutex); | 385 | mutex_lock(&chip->tpm_mutex); |
384 | 386 | ||
385 | if ((rc = chip->vendor.send(chip, (u8 *) buf, count)) < 0) { | 387 | if ((rc = chip->vendor.send(chip, (u8 *) buf, count)) < 0) { |
386 | dev_err(chip->dev, | 388 | dev_err(chip->dev, |
@@ -419,7 +421,7 @@ out_recv: | |||
419 | dev_err(chip->dev, | 421 | dev_err(chip->dev, |
420 | "tpm_transmit: tpm_recv: error %zd\n", rc); | 422 | "tpm_transmit: tpm_recv: error %zd\n", rc); |
421 | out: | 423 | out: |
422 | up(&chip->tpm_mutex); | 424 | mutex_unlock(&chip->tpm_mutex); |
423 | return rc; | 425 | return rc; |
424 | } | 426 | } |
425 | 427 | ||
@@ -966,14 +968,14 @@ ssize_t tpm_write(struct file *file, const char __user *buf, | |||
966 | while (atomic_read(&chip->data_pending) != 0) | 968 | while (atomic_read(&chip->data_pending) != 0) |
967 | msleep(TPM_TIMEOUT); | 969 | msleep(TPM_TIMEOUT); |
968 | 970 | ||
969 | down(&chip->buffer_mutex); | 971 | mutex_lock(&chip->buffer_mutex); |
970 | 972 | ||
971 | if (in_size > TPM_BUFSIZE) | 973 | if (in_size > TPM_BUFSIZE) |
972 | in_size = TPM_BUFSIZE; | 974 | in_size = TPM_BUFSIZE; |
973 | 975 | ||
974 | if (copy_from_user | 976 | if (copy_from_user |
975 | (chip->data_buffer, (void __user *) buf, in_size)) { | 977 | (chip->data_buffer, (void __user *) buf, in_size)) { |
976 | up(&chip->buffer_mutex); | 978 | mutex_unlock(&chip->buffer_mutex); |
977 | return -EFAULT; | 979 | return -EFAULT; |
978 | } | 980 | } |
979 | 981 | ||
@@ -981,7 +983,7 @@ ssize_t tpm_write(struct file *file, const char __user *buf, | |||
981 | out_size = tpm_transmit(chip, chip->data_buffer, TPM_BUFSIZE); | 983 | out_size = tpm_transmit(chip, chip->data_buffer, TPM_BUFSIZE); |
982 | 984 | ||
983 | atomic_set(&chip->data_pending, out_size); | 985 | atomic_set(&chip->data_pending, out_size); |
984 | up(&chip->buffer_mutex); | 986 | mutex_unlock(&chip->buffer_mutex); |
985 | 987 | ||
986 | /* Set a timeout by which the reader must come claim the result */ | 988 | /* Set a timeout by which the reader must come claim the result */ |
987 | mod_timer(&chip->user_read_timer, jiffies + (60 * HZ)); | 989 | mod_timer(&chip->user_read_timer, jiffies + (60 * HZ)); |
@@ -1004,10 +1006,10 @@ ssize_t tpm_read(struct file *file, char __user *buf, | |||
1004 | if (size < ret_size) | 1006 | if (size < ret_size) |
1005 | ret_size = size; | 1007 | ret_size = size; |
1006 | 1008 | ||
1007 | down(&chip->buffer_mutex); | 1009 | mutex_lock(&chip->buffer_mutex); |
1008 | if (copy_to_user(buf, chip->data_buffer, ret_size)) | 1010 | if (copy_to_user(buf, chip->data_buffer, ret_size)) |
1009 | ret_size = -EFAULT; | 1011 | ret_size = -EFAULT; |
1010 | up(&chip->buffer_mutex); | 1012 | mutex_unlock(&chip->buffer_mutex); |
1011 | } | 1013 | } |
1012 | 1014 | ||
1013 | return ret_size; | 1015 | return ret_size; |
@@ -1105,8 +1107,8 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend | |||
1105 | return NULL; | 1107 | return NULL; |
1106 | } | 1108 | } |
1107 | 1109 | ||
1108 | init_MUTEX(&chip->buffer_mutex); | 1110 | mutex_init(&chip->buffer_mutex); |
1109 | init_MUTEX(&chip->tpm_mutex); | 1111 | mutex_init(&chip->tpm_mutex); |
1110 | INIT_LIST_HEAD(&chip->list); | 1112 | INIT_LIST_HEAD(&chip->list); |
1111 | 1113 | ||
1112 | INIT_WORK(&chip->work, timeout_work); | 1114 | INIT_WORK(&chip->work, timeout_work); |