• Maciej W. Rozycki's avatar
    rtc: rtc_time_to_tm: use unsigned arithmetic · 945185a6
    Maciej W. Rozycki authored
    The input argument to rtc_time_to_tm() is unsigned as well as are members of
    the output structure.  However signed arithmetic is used within for
    calculations leading to incorrect results for input values outside the signed
    positive range.  If this happens the time of day returned is out of range.
    
    Found the problem when fiddling with the RTC and the driver where year was set
    to an unexpectedly large value like 2070, e.g.:
    
    rtc0: setting system clock to 2070-01-01 1193046:71582832:26 UTC (3155760954)
    
    while it should be:
    
    rtc0: setting system clock to 2070-01-01 00:15:54 UTC (3155760954)
    
    Changing types to unsigned fixes the problem.
    
    [akpm@linux-foundation.org: remove old-fashioned `register' keyword]
    Signed-off-by: default avatarMaciej W. Rozycki <macro@linux-mips.org>
    Cc: Alessandro Zummo <a.zummo@towertech.it>
    Cc: David Brownell <david-b@pacbell.net>
    Cc: Dmitri Vorobiev <dmitri.vorobiev@gmail.com>
    Cc: <stable@kernel.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    945185a6
rtc-lib.c 2.85 KB