提交 5b44bd58 编写于 作者: K Kylene Hall 提交者: Linus Torvalds

[PATCH] tpm: read return code issue

Replace an erroneous return code for the read function when no data is
available.
Signed-of-by: NKylene Hall <kjhall@us.ibm.com>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 f87ea32a
...@@ -489,29 +489,19 @@ ssize_t tpm_read(struct file * file, char __user * buf, ...@@ -489,29 +489,19 @@ ssize_t tpm_read(struct file * file, char __user * buf,
size_t size, loff_t * off) size_t size, loff_t * off)
{ {
struct tpm_chip *chip = file->private_data; struct tpm_chip *chip = file->private_data;
int ret_size = -ENODATA; int ret_size;
if (atomic_read(&chip->data_pending) != 0) { /* Result available */ del_singleshot_timer_sync(&chip->user_read_timer);
down(&chip->timer_manipulation_mutex); ret_size = atomic_read(&chip->data_pending);
del_singleshot_timer_sync(&chip->user_read_timer); atomic_set(&chip->data_pending, 0);
up(&chip->timer_manipulation_mutex); if (ret_size > 0) { /* relay data */
if (size < ret_size)
ret_size = size;
down(&chip->buffer_mutex); down(&chip->buffer_mutex);
if (copy_to_user
ret_size = atomic_read(&chip->data_pending); ((void __user *) buf, chip->data_buffer, ret_size))
atomic_set(&chip->data_pending, 0); ret_size = -EFAULT;
if (ret_size == 0) /* timeout just occurred */
ret_size = -ETIME;
else if (ret_size > 0) { /* relay data */
if (size < ret_size)
ret_size = size;
if (copy_to_user((void __user *) buf,
chip->data_buffer, ret_size)) {
ret_size = -EFAULT;
}
}
up(&chip->buffer_mutex); up(&chip->buffer_mutex);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册