public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dmitri Vorobiev <dmitri.vorobiev@gmail.com>
To: "Maciej W. Rozycki" <macro@linux-mips.org>
Cc: Alessandro Zummo <a.zummo@towertech.it>,
	Andrew Morton <akpm@linux-foundation.org>,
	rtc-linux@googlegroups.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] RTC: rtc_time_to_tm: use unsigned arithmetic
Date: Wed, 07 May 2008 02:50:46 +0400	[thread overview]
Message-ID: <4820E0C6.10309@gmail.com> (raw)
In-Reply-To: <Pine.LNX.4.55.0805062315530.16173@cliff.in.clinika.pl>

Maciej W. Rozycki пишет:
>  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.
> 
> Signed-off-by: Maciej W. Rozycki <macro@linux-mips.org>
> ---
>  Tested on 64-bit MIPS.  Please apply.
> 
>   Maciej
> 
> patch-2.6.26-rc1-20080505-rtc-time-unsigned-11
> diff -up --recursive --new-file linux-2.6.26-rc1-20080505.macro/drivers/rtc/rtc-lib.c linux-2.6.26-rc1-20080505/drivers/rtc/rtc-lib.c
> --- linux-2.6.26-rc1-20080505.macro/drivers/rtc/rtc-lib.c	2007-07-10 04:56:26.000000000 +0000
> +++ linux-2.6.26-rc1-20080505/drivers/rtc/rtc-lib.c	2008-05-05 02:37:38.000000000 +0000
> @@ -51,7 +51,7 @@ EXPORT_SYMBOL(rtc_year_days);
>   */
>  void rtc_time_to_tm(unsigned long time, struct rtc_time *tm)
>  {
> -	register int days, month, year;
> +	register unsigned int days, month, year;

Does it make any sense to use the `register' keyword nowadays?

Dmitri

  reply	other threads:[~2008-05-06 22:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-06 22:31 [PATCH] RTC: rtc_time_to_tm: use unsigned arithmetic Maciej W. Rozycki
2008-05-06 22:50 ` Dmitri Vorobiev [this message]
2008-05-07  1:11   ` Maciej W. Rozycki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4820E0C6.10309@gmail.com \
    --to=dmitri.vorobiev@gmail.com \
    --cc=a.zummo@towertech.it \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=macro@linux-mips.org \
    --cc=rtc-linux@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox