diff options
author | Nishanth Aravamudan <nacc@us.ibm.com> | 2005-06-24 01:01:47 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-06-24 03:05:24 -0400 |
commit | 700d8bdcd0fa815b08638b1e4d43b66d60cc6a8d (patch) | |
tree | c3defbf1cb77b9290a002cff04e1b2f054dfcb05 /drivers/char/tpm/tpm.c | |
parent | 6a94f9209762a6eb286f668e1346ad87985cc765 (diff) |
[PATCH] char/tpm: use msleep(), clean-up timers,
The TPM driver unnecessarily uses timers when it simply needs to maintain a
maximum delay via time_before(). msleep() is used instead of
schedule_timeout() to guarantee the task delays as expected. While
compile-testing, I found a typo in the driver, using tpm_chp instead of
tpm_chip. Remove the now unused timer callback function and change
TPM_TIMEOUT's units to milliseconds. Patch is compile-tested.
Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>
Acked-by: Kylene Hall <kjhall@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/char/tpm/tpm.c')
-rw-r--r-- | drivers/char/tpm/tpm.c | 35 |
1 files changed, 7 insertions, 28 deletions
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c index 8ce508b29865..c937ea2bcdbc 100644 --- a/drivers/char/tpm/tpm.c +++ b/drivers/char/tpm/tpm.c | |||
@@ -19,7 +19,7 @@ | |||
19 | * | 19 | * |
20 | * Note, the TPM chip is not interrupt driven (only polling) | 20 | * Note, the TPM chip is not interrupt driven (only polling) |
21 | * and can have very long timeouts (minutes!). Hence the unusual | 21 | * and can have very long timeouts (minutes!). Hence the unusual |
22 | * calls to schedule_timeout. | 22 | * calls to msleep. |
23 | * | 23 | * |
24 | */ | 24 | */ |
25 | 25 | ||
@@ -52,14 +52,6 @@ static void user_reader_timeout(unsigned long ptr) | |||
52 | up(&chip->buffer_mutex); | 52 | up(&chip->buffer_mutex); |
53 | } | 53 | } |
54 | 54 | ||
55 | void tpm_time_expired(unsigned long ptr) | ||
56 | { | ||
57 | int *exp = (int *) ptr; | ||
58 | *exp = 1; | ||
59 | } | ||
60 | |||
61 | EXPORT_SYMBOL_GPL(tpm_time_expired); | ||
62 | |||
63 | /* | 55 | /* |
64 | * Initialize the LPC bus and enable the TPM ports | 56 | * Initialize the LPC bus and enable the TPM ports |
65 | */ | 57 | */ |
@@ -135,6 +127,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, | |||
135 | ssize_t len; | 127 | ssize_t len; |
136 | u32 count; | 128 | u32 count; |
137 | __be32 *native_size; | 129 | __be32 *native_size; |
130 | unsigned long stop; | ||
138 | 131 | ||
139 | native_size = (__force __be32 *) (buf + 2); | 132 | native_size = (__force __be32 *) (buf + 2); |
140 | count = be32_to_cpu(*native_size); | 133 | count = be32_to_cpu(*native_size); |
@@ -155,28 +148,16 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, | |||
155 | return len; | 148 | return len; |
156 | } | 149 | } |
157 | 150 | ||
158 | down(&chip->timer_manipulation_mutex); | 151 | stop = jiffies + 2 * 60 * HZ; |
159 | chip->time_expired = 0; | ||
160 | init_timer(&chip->device_timer); | ||
161 | chip->device_timer.function = tpm_time_expired; | ||
162 | chip->device_timer.expires = jiffies + 2 * 60 * HZ; | ||
163 | chip->device_timer.data = (unsigned long) &chip->time_expired; | ||
164 | add_timer(&chip->device_timer); | ||
165 | up(&chip->timer_manipulation_mutex); | ||
166 | |||
167 | do { | 152 | do { |
168 | u8 status = inb(chip->vendor->base + 1); | 153 | u8 status = inb(chip->vendor->base + 1); |
169 | if ((status & chip->vendor->req_complete_mask) == | 154 | if ((status & chip->vendor->req_complete_mask) == |
170 | chip->vendor->req_complete_val) { | 155 | chip->vendor->req_complete_val) { |
171 | down(&chip->timer_manipulation_mutex); | ||
172 | del_singleshot_timer_sync(&chip->device_timer); | ||
173 | up(&chip->timer_manipulation_mutex); | ||
174 | goto out_recv; | 156 | goto out_recv; |
175 | } | 157 | } |
176 | set_current_state(TASK_UNINTERRUPTIBLE); | 158 | msleep(TPM_TIMEOUT); /* CHECK */ |
177 | schedule_timeout(TPM_TIMEOUT); | ||
178 | rmb(); | 159 | rmb(); |
179 | } while (!chip->time_expired); | 160 | } while (time_before(jiffies, stop)); |
180 | 161 | ||
181 | 162 | ||
182 | chip->vendor->cancel(chip); | 163 | chip->vendor->cancel(chip); |
@@ -453,10 +434,8 @@ ssize_t tpm_write(struct file * file, const char __user * buf, | |||
453 | 434 | ||
454 | /* cannot perform a write until the read has cleared | 435 | /* cannot perform a write until the read has cleared |
455 | either via tpm_read or a user_read_timer timeout */ | 436 | either via tpm_read or a user_read_timer timeout */ |
456 | while (atomic_read(&chip->data_pending) != 0) { | 437 | while (atomic_read(&chip->data_pending) != 0) |
457 | set_current_state(TASK_UNINTERRUPTIBLE); | 438 | msleep(TPM_TIMEOUT); |
458 | schedule_timeout(TPM_TIMEOUT); | ||
459 | } | ||
460 | 439 | ||
461 | down(&chip->buffer_mutex); | 440 | down(&chip->buffer_mutex); |
462 | 441 | ||