Skip to content

Commit

Permalink
[PARISC] Fix do_gettimeofday() hang
Browse files Browse the repository at this point in the history
Apparently gettimeoffset can return small negative values (usually in
the 100us range).  If xtime.tv_nsec is accidentally less than this,
though (a fortunately unlikely event) it triggers the loop forever.

I've added a test and correct adjustment for this case.  It has a
warning printk in there which I'd like to leave for the time being
just in case this problem implicates some other part of the kernel.

Signed-off-by: James Bottomley <jejb@parisc-linux.org>
Signed-off-by: Kyle McMartin <kyle@parisc-linux.org>
  • Loading branch information
James Bottomley authored and Kyle McMartin committed Jun 27, 2006
1 parent 6e1b958 commit 61c3401
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions arch/parisc/kernel/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,22 @@ do_gettimeofday (struct timeval *tv)
usec += (xtime.tv_nsec / 1000);
} while (read_seqretry_irqrestore(&xtime_lock, seq, flags));

while (usec >= 1000000) {
usec -= 1000000;
if (unlikely(usec > LONG_MAX)) {
/* This can happen if the gettimeoffset adjustment is
* negative and xtime.tv_nsec is smaller than the
* adjustment */
printk(KERN_ERR "do_gettimeofday() spurious xtime.tv_nsec of %ld\n", usec);
usec += USEC_PER_SEC;
--sec;
/* This should never happen, it means the negative
* time adjustment was more than a second, so there's
* something seriously wrong */
BUG_ON(usec > LONG_MAX);
}


while (usec >= USEC_PER_SEC) {
usec -= USEC_PER_SEC;
++sec;
}

Expand Down

0 comments on commit 61c3401

Please sign in to comment.