]> nv-tegra.nvidia Code Review - linux-3.10.git/commitdiff
drivers/rtc/rtc-rs5c348.c: fix hour decoding in 12-hour mode
authorAtsushi Nemoto <anemo@mba.ocn.ne.jp>
Tue, 21 Aug 2012 23:16:10 +0000 (16:16 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 21 Aug 2012 23:45:03 +0000 (16:45 -0700)
Correct the offset by subtracting 20 from tm_hour before taking the
modulo 12.

[ "Why 20?" I hear you ask. Or at least I did.

  Here's the reason why: RS5C348_BIT_PM is 32, and is - stupidly -
  included in the RS5C348_HOURS_MASK define.  So it's really subtracting
  out that bit to get "hour+12".  But then because it does things modulo
  12, it needs to add the 12 in again afterwards anyway.

  This code is confused.  It would be much clearer if RS5C348_HOURS_MASK
  just didn't include the RS5C348_BIT_PM bit at all, then it wouldn't
  need to do the silly subtract either.

  Whatever. It's all just math, the end result is the same.   - Linus ]

Reported-by: James Nute <newten82@gmail.com>
Tested-by: James Nute <newten82@gmail.com>
Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/rtc/rtc-rs5c348.c

index 77074ccd285071f345118079a4f7c3120e6b86a3..fd5c7af04ae5a7d7c1ba30a5822396e6780adc5f 100644 (file)
@@ -122,9 +122,12 @@ rs5c348_rtc_read_time(struct device *dev, struct rtc_time *tm)
        tm->tm_min = bcd2bin(rxbuf[RS5C348_REG_MINS] & RS5C348_MINS_MASK);
        tm->tm_hour = bcd2bin(rxbuf[RS5C348_REG_HOURS] & RS5C348_HOURS_MASK);
        if (!pdata->rtc_24h) {
-               tm->tm_hour %= 12;
-               if (rxbuf[RS5C348_REG_HOURS] & RS5C348_BIT_PM)
+               if (rxbuf[RS5C348_REG_HOURS] & RS5C348_BIT_PM) {
+                       tm->tm_hour -= 20;
+                       tm->tm_hour %= 12;
                        tm->tm_hour += 12;
+               } else
+                       tm->tm_hour %= 12;
        }
        tm->tm_wday = bcd2bin(rxbuf[RS5C348_REG_WDAY] & RS5C348_WDAY_MASK);
        tm->tm_mday = bcd2bin(rxbuf[RS5C348_REG_DAY] & RS5C348_DAY_MASK);