Skip to content

Commit

Permalink
rtc: test before subtraction on unsigned
Browse files Browse the repository at this point in the history
new_alarm is unsigned so test before the subtraction.

[akpm@linux-foundation.org: time-wrapping fix]
Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
Cc: David Brownell <david-b@pacbell.net>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Roel Kluin authored and Linus Torvalds committed Apr 1, 2009
1 parent c08cf9d commit fa7af8b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/rtc/rtc-ds1374.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,16 @@ static int ds1374_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
rtc_tm_to_time(&alarm->time, &new_alarm);
rtc_tm_to_time(&now, &itime);

new_alarm -= itime;

/* This can happen due to races, in addition to dates that are
* truly in the past. To avoid requiring the caller to check for
* races, dates in the past are assumed to be in the recent past
* (i.e. not something that we'd rather the caller know about via
* an error), and the alarm is set to go off as soon as possible.
*/
if (new_alarm <= 0)
if (time_before_eq(new_alarm, itime))
new_alarm = 1;
else
new_alarm -= itime;

mutex_lock(&ds1374->mutex);

Expand Down

0 comments on commit fa7af8b

Please sign in to comment.