Skip to content

Commit

Permalink
x86: HPET fix moronic 32/64bit thinko
Browse files Browse the repository at this point in the history
We use the HPET only in 32bit mode because:
1) some HPETs are 32bit only
2) on i386 there is no way to read/write the HPET atomic 64bit wide

The HPET code unification done by the "moron of the year" did
not take into account that unsigned long is different on 32 and
64 bit.

This thinko results in a possible endless loop in the clockevents
code, when the return comparison fails due to the 64bit/332bit
unawareness. 

unsigned long cnt = (u32) hpet_read() + delta can wrap over 32bit.
but the final compare will fail and return -ETIME causing endless
loops.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
  • Loading branch information
Thomas Gleixner committed Sep 6, 2008
1 parent 7300711 commit f767625
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions arch/x86/kernel/hpet.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,15 @@ static void hpet_legacy_set_mode(enum clock_event_mode mode,
}

static int hpet_legacy_next_event(unsigned long delta,
struct clock_event_device *evt)
struct clock_event_device *evt)
{
unsigned long cnt;
u32 cnt;

cnt = hpet_readl(HPET_COUNTER);
cnt += delta;
cnt += (u32) delta;
hpet_writel(cnt, HPET_T0_CMP);

return ((long)(hpet_readl(HPET_COUNTER) - cnt ) > 0) ? -ETIME : 0;
return (s32)((u32)hpet_readl(HPET_COUNTER) - cnt) >= 0 ? -ETIME : 0;
}

/*
Expand Down

0 comments on commit f767625

Please sign in to comment.