Memtest86+: Fix potential integer overflow in spd.c

Coverity spotted a potential integer overflow in this code.

  int32_t l1, h1, l2, h2;
  uint64_t t;
  rdtsc(l1, h1);
  while (...) {
    rdtsc(l2, h2);
    t = ((h2 - h1) * 0xffffffff + (l2 - l1)) / v->clks_msec;
    if (t > 10) break;

If the upper 32-bits of the TSC changes during the wait and the SMB
controller stops working, the code could loop for a very long time.
Highly unlikely.

We can't just cast (h2 - h1) to uint64_t, because then gcc wants __udivdi3
for the 64-bit divide.  Better to rework the code to discard the 64 bit
divide altogether and remove the divide from the loop.

Change-Id: I196fbc04ce80a1edd2449db8a7288ccde415d522
Signed-off-by: Ben Gardner <>
Found-by: Coverity (75585, 75586)
Tested-by: build bot (Jenkins)
Reviewed-by: Martin Roth <>
1 file changed