[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>
这个提交包含在:
Nishanth Aravamudan
2005-06-23 22:01:47 -07:00
提交者 Linus Torvalds
父节点 6a94f92097
当前提交 700d8bdcd0
修改 3 个文件,包含 18 行新增52 行删除

查看文件

@@ -55,10 +55,7 @@
*/
static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data)
{
int expired = 0;
struct timer_list status_timer =
TIMER_INITIALIZER(tpm_time_expired, jiffies + 10 * HZ,
(unsigned long) &expired);
unsigned long stop;
/* status immediately available check */
*data = inb(chip->vendor->base + NSC_STATUS);
@@ -66,17 +63,14 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data)
return 0;
/* wait for status */
add_timer(&status_timer);
stop = jiffies + 10 * HZ;
do {
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(TPM_TIMEOUT);
msleep(TPM_TIMEOUT);
*data = inb(chip->vendor->base + 1);
if ((*data & mask) == val) {
del_singleshot_timer_sync(&status_timer);
if ((*data & mask) == val)
return 0;
}
}
while (!expired);
while (time_before(jiffies, stop));
return -EBUSY;
}
@@ -84,10 +78,7 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data)
static int nsc_wait_for_ready(struct tpm_chip *chip)
{
int status;
int expired = 0;
struct timer_list status_timer =
TIMER_INITIALIZER(tpm_time_expired, jiffies + 100,
(unsigned long) &expired);
unsigned long stop;
/* status immediately available check */
status = inb(chip->vendor->base + NSC_STATUS);
@@ -97,19 +88,16 @@ static int nsc_wait_for_ready(struct tpm_chip *chip)
return 0;
/* wait for status */
add_timer(&status_timer);
stop = jiffies + 100;
do {
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(TPM_TIMEOUT);
msleep(TPM_TIMEOUT);
status = inb(chip->vendor->base + NSC_STATUS);
if (status & NSC_STATUS_OBF)
status = inb(chip->vendor->base + NSC_DATA);
if (status & NSC_STATUS_RDY) {
del_singleshot_timer_sync(&status_timer);
if (status & NSC_STATUS_RDY)
return 0;
}
}
while (!expired);
while (time_before(jiffies, stop));
dev_info(&chip->pci_dev->dev, "wait for ready failed\n");
return -EBUSY;