Skip to content

Commit

Permalink
hpet: fix the possibility of insane return value of hpet_calibrate() …
Browse files Browse the repository at this point in the history
…against SMI

hpet_calibrate() has a possibility of miss-calibration due to SMI.  If SMI
interrupts in the while loop of calibration, then return value will be
big.  This change calibrates until stabilizing by the return value with a
small value.

[[email protected]: trivial style tweaks]
Signed-off-by: Yasunori Goto <[email protected]>
Acked-by: Clemens Ladisch <[email protected]>
Acked-by: Vojtech Pavlik <[email protected]>
Cc: Robert Picco <[email protected]>
Cc: Venkatesh Pallipadi <[email protected]>
Cc: Ingo Molnar <[email protected]>
Acked-by: Paul Gortmaker <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Yasunori Goto authored and torvalds committed Apr 3, 2009
1 parent 1f80769 commit 303d379
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion drivers/char/hpet.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ static struct ctl_table_header *sysctl_header;
*/
#define TICK_CALIBRATE (1000UL)

static unsigned long hpet_calibrate(struct hpets *hpetp)
static unsigned long __hpet_calibrate(struct hpets *hpetp)
{
struct hpet_timer __iomem *timer = NULL;
unsigned long t, m, count, i, flags, start;
Expand Down Expand Up @@ -750,6 +750,26 @@ static unsigned long hpet_calibrate(struct hpets *hpetp)
return (m - start) / i;
}

static unsigned long hpet_calibrate(struct hpets *hpetp)
{
unsigned long ret = -1;
unsigned long tmp;

/*
* Try to calibrate until return value becomes stable small value.
* If SMI interruption occurs in calibration loop, the return value
* will be big. This avoids its impact.
*/
for ( ; ; ) {
tmp = __hpet_calibrate(hpetp);
if (ret <= tmp)
break;
ret = tmp;
}

return ret;
}

int hpet_alloc(struct hpet_data *hdp)
{
u64 cap, mcfg;
Expand Down

0 comments on commit 303d379

Please sign in to comment.