ia64/xen-unstable

view patches/linux-2.6.12/tpm_partial_read.patch @ 6923:03b58a6f498e

Remove native tpm drivers from the linux sparse tree and replace
with minimal patch in the automatically-applied patches/ directory.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author kaf24@firebug.cl.cam.ac.uk
date Sat Sep 17 08:25:30 2005 +0000 (2005-09-17)
parents
children 06d84bf87159
line source
1 --- ref-linux-2.6.12/drivers/char/tpm/tpm.c 2005-06-17 15:48:29.000000000 -0400
2 +++ linux-2.6-xen-sparse/drivers/char/tpm/tpm.c 2005-09-15 14:56:05.000000000 -0400
3 @@ -473,6 +401,7 @@ ssize_t tpm_write(struct file * file, co
4 out_size = tpm_transmit(chip, chip->data_buffer, TPM_BUFSIZE);
6 atomic_set(&chip->data_pending, out_size);
7 + atomic_set(&chip->data_position, 0);
8 up(&chip->buffer_mutex);
10 /* Set a timeout by which the reader must come claim the result */
11 @@ -494,29 +423,34 @@ ssize_t tpm_read(struct file * file, cha
12 {
13 struct tpm_chip *chip = file->private_data;
14 int ret_size = -ENODATA;
15 + int pos, pending = 0;
17 - if (atomic_read(&chip->data_pending) != 0) { /* Result available */
18 + down(&chip->buffer_mutex);
19 + ret_size = atomic_read(&chip->data_pending);
20 + if ( ret_size > 0 ) { /* Result available */
21 + if (size < ret_size)
22 + ret_size = size;
23 +
24 + pos = atomic_read(&chip->data_position);
25 +
26 + if (copy_to_user((void __user *) buf,
27 + &chip->data_buffer[pos], ret_size)) {
28 + ret_size = -EFAULT;
29 + } else {
30 + pending = atomic_read(&chip->data_pending) - ret_size;
31 + if ( pending ) {
32 + atomic_set( &chip->data_pending, pending );
33 + atomic_set( &chip->data_position, pos+ret_size );
34 + }
35 + }
36 + }
37 + up(&chip->buffer_mutex);
38 +
39 + if ( ret_size <= 0 || pending == 0 ) {
40 + atomic_set( &chip->data_pending, 0 );
41 down(&chip->timer_manipulation_mutex);
42 del_singleshot_timer_sync(&chip->user_read_timer);
43 up(&chip->timer_manipulation_mutex);
44 -
45 - down(&chip->buffer_mutex);
46 -
47 - ret_size = atomic_read(&chip->data_pending);
48 - atomic_set(&chip->data_pending, 0);
49 -
50 - if (ret_size == 0) /* timeout just occurred */
51 - ret_size = -ETIME;
52 - else if (ret_size > 0) { /* relay data */
53 - if (size < ret_size)
54 - ret_size = size;
55 -
56 - if (copy_to_user((void __user *) buf,
57 - chip->data_buffer, ret_size)) {
58 - ret_size = -EFAULT;
59 - }
60 - }
61 - up(&chip->buffer_mutex);
62 }
64 return ret_size;
65 --- ref-linux-2.6.12/drivers/char/tpm/tpm.h 2005-06-17 15:48:29.000000000 -0400
66 +++ linux-2.6-xen-sparse/drivers/char/tpm/tpm.h 2005-09-15 14:56:05.000000000 -0400
67 @@ -54,6 +54,7 @@ struct tpm_chip {
68 /* Data passed to and from the tpm via the read/write calls */
69 u8 *data_buffer;
70 atomic_t data_pending;
71 + atomic_t data_position;
72 struct semaphore buffer_mutex;
74 struct timer_list user_read_timer; /* user needs to claim result */