Re: [RFC PATCH v2 04/11] time: Add rtc_time_to_tm64() safe version(using time64_t)
From: Thomas Gleixner
Date: Thu Oct 30 2014 - 10:07:12 EST
On Thu, 30 Oct 2014, pang.xunlei wrote:
As you can guess already: $subject sucks.
> +
> /*
> * Convert seconds since 01-01-1970 00:00:00 to Gregorian date.
> + * Safe version for 2038 safety.
See previous replies.
> */
> -void rtc_time_to_tm(unsigned long time, struct rtc_time *tm)
> +void rtc_time_to_tm64(time64_t time, struct rtc_time *tm)
What's tm64?
This function is converting time64 to rtc_time. So the proper function
name is: rtc_time64_to_tm
Can you see the difference?
> {
> unsigned int month, year;
> int days;
>
> - days = time / 86400;
> + days = div_s64(time, 86400);
> time -= (unsigned int) days * 86400;
>
> /* day of the week, 1970-01-01 was a Thursday */
> @@ -81,13 +83,23 @@ void rtc_time_to_tm(unsigned long time, struct rtc_time *tm)
> tm->tm_mon = month;
> tm->tm_mday = days + 1;
>
> - tm->tm_hour = time / 3600;
> + tm->tm_hour = div_s64(time, 3600);
We already adjusted time to a value which is less than 24 * 3600,
i.e. it fits nicely into a long on 32bit. So we can avoid the whole
div_s64 business and simply do:
unsigned int month, year;
+ unsigned long secs;
int days;
- days = time / 86400;
- time -= (unsigned int) days * 86400;
+ days = div_s64(time, 86400);
+ secs = time - (unsigned int) days * 86400;
And change the rest which uses time to:
- tm->tm_hour = time / 3600;
+ tm->tm_hour = secs / 3600;
Sigh.
tglx
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/