[PATCH] powermac: proper time of day after resume

Paul Mackerras paulus at samba.org
Wed May 2 14:45:00 EST 2007


Johannes Berg writes:

> +static int timer_resume(struct sys_device *dev)
> +{
> +	struct timeval tv;
> +	struct timespec ts;
> +	struct rtc_time cur_rtc_tm;
> +	unsigned long cur_rtc_time, diff;
> +
> +	/* get current RTC time and convert to seconds */
> +	get_rtc_time(&cur_rtc_tm);
> +	rtc_tm_to_time(&cur_rtc_tm, &cur_rtc_time);

Why not just use get_boot_time() here?  Or if not that, then use
mktime() instead of rtc_tm_to_time().  Either way we don't need to
select RTC_LIB.

> +	diff = cur_rtc_time - suspend_rtc_time;
> +
> +	/* adjust time of day by seconds that elapsed while
> +	 * we were suspended */
> +	do_gettimeofday(&tv);
> +	ts.tv_sec = tv.tv_sec + diff;
> +	ts.tv_nsec = tv.tv_usec * NSEC_PER_USEC;
> +	do_settimeofday(&ts);

This will fail if ts.tv_nsec ends up being >= NSEC_PER_SEC.

Paul.



More information about the Linuxppc-dev mailing list