Date: Mon, 31 Dec 2001 16:14:08 +0100
From: Nils Faerber <nils@kernelconcepts.de>
To: mzyngier@freesurf.fr
Cc: Jamey.Hicks@compaq.com, ipaq@handhelds.org
Subject: Re: [iPAQ] freeze at system clock
Nils Faerber <nils@kernelconcepts.de> wrote:
> Nils Faerber <nils@kernelconcepts.de> wrote:
>
> > Nils Faerber <nils@kernelconcepts.de> wrote:
> > > Any idea on how to fix that ?
> > Think so ;)
> > Someone introduced a bug in the SET_TIME ioctl() of the driver.
> > The month is tested against >= 12 and not > 12 as it ought to be.
> > As a result the december is an illegal month :(
> > At least that's my theory for now ;)
> > I see if I can really fix it and send a patch if it worked.
> OK, this was wrong ;)
> Months are the only exception and really are 0 <= month < 12 :)
> But the table containing the number of days in a month was wrong and
> assumed months starting at 1; if you try setting a day in January you will
> see the same fault.
This is also wrong. The bug depends on a particular date either with alarm
or clock adjustment to enter an endless loop.
Please back out any changes from the handhelds.org CVS so the original
driver as found in the unmodified -rmk tree is there again.
Next apply this patch:
--- orig/linux/drivers/char/sa1100-rtc.c Sun Dec 9 20:51:51 2001
+++ linux/drivers/char/sa1100-rtc.c Thu Jan 3 15:37:33 2002
@@ -78,7 +78,7 @@
static void decodetime (unsigned long t, struct rtc_time *tval)
{
- unsigned long days, month, year, rem;
+ long days, month, year, rem;
days = t / 86400;
rem = t % 86400;
@@ -90,13 +90,13 @@
#define LEAPS_THRU_END_OF(y) ((y)/4 - (y)/100 + (y)/400)
- year = epoch;
- while (days >= (365 + is_leap(year))) {
- unsigned long yg = year + days / 365;
- days -= ((yg - year) * 365
- + LEAPS_THRU_END_OF (yg - 1)
- - LEAPS_THRU_END_OF (year - 1));
- year = yg;
+ year = epoch + days / 365;
+ days -= ((year - epoch) * 365
+ + LEAPS_THRU_END_OF (year - 1)
+ - LEAPS_THRU_END_OF (epoch - 1));
+ if (days < 0) {
+ year -= 1;
+ days += 365 + is_leap(year);
}
tval->tm_year = year - 1900;
tval->tm_yday = days + 1;
Problem fixed. Also tested with all possible dates from Jan 01, 1970
through something 2100ish for correctness.
The version since the 2.4.17-rmk2 release is already fixed and doesn't
require any patching.
GENERAL NOTE TO EVERYBODY:
If further problems occur with the RTC driver _please_ provide a detailed
bug report with the exact command sequence that took place, their arguments,
the value of 'date' _before_ a failing 'hwclock -w', etc. The current
system date at which bugs occur in a RTC driver is important.
In all cases I'll be interested to get those bug reports.
Nicolas
Received on Thu Jan 3 17:38:21 2002
This archive was generated by hypermail 2.1.8 : Tue May 04 2004 - 09:44:20 EDT