Re: [tip:tools/kvm] kvm tools: Fix reported year in RTC emulation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm embarrassed, the comment matcheth not the code. Oops.

"if year is > 99, subtract 100 etc."

Or just yank all my words starting with "If the year ..."

Sorry. I'll never make this mistake again, at least until we run out
of BCD digits.

ron

On Fri, Oct 19, 2012 at 12:54 PM, tip-bot for Ronald G. Minnich
<rminnich@xxxxxxxxx> wrote:
> Commit-ID:  13d509712aa10399af28935fda45d4a5f0c9bb1f
> Gitweb:     http://git.kernel.org/tip/13d509712aa10399af28935fda45d4a5f0c9bb1f
> Author:     Ronald G. Minnich <rminnich@xxxxxxxxx>
> AuthorDate: Mon, 15 Oct 2012 09:20:22 -0700
> Committer:  Pekka Enberg <penberg@xxxxxxxxxx>
> CommitDate: Tue, 16 Oct 2012 10:33:08 +0300
>
> kvm tools: Fix reported year in RTC emulation
>
> The gmtime() function returns the number of years since 1900.
>
> On PCs, the "design" of CMOS dates is such that the years (in this case)
> are years since 2000. Fix up RTC emulation as follows:
>
>  - if year is > 99, subtract 100
>  - if year is  99 (20th century) take it as it is
>
> Signed-off-by: Ronald G. Minnich <rminnich@xxxxxxxxx>
> [ penberg@xxxxxxxxxx: cleanups ]
> Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx>
> ---
>  tools/kvm/hw/rtc.c |   12 +++++++++++-
>  1 files changed, 11 insertions(+), 1 deletions(-)
>
> diff --git a/tools/kvm/hw/rtc.c b/tools/kvm/hw/rtc.c
> index ad6dd65..4a862d6 100644
> --- a/tools/kvm/hw/rtc.c
> +++ b/tools/kvm/hw/rtc.c
> @@ -40,6 +40,7 @@ static bool cmos_ram_data_in(struct ioport *ioport, struct kvm *kvm, u16 port, v
>  {
>         struct tm *tm;
>         time_t ti;
> +       int year;
>
>         time(&ti);
>
> @@ -65,7 +66,16 @@ static bool cmos_ram_data_in(struct ioport *ioport, struct kvm *kvm, u16 port, v
>                 ioport__write8(data, bin2bcd(tm->tm_mon + 1));
>                 break;
>         case RTC_YEAR:
> -               ioport__write8(data, bin2bcd(tm->tm_year));
> +               /*
> +                * The gmtime() function returns time since 1900. The CMOS
> +                * standard is time since 2000. If the year is < 100, do
> +                * nothing; if it is > 100, subtract 100; this is the best fit
> +                * with the twisted CMOS logic.
> +                */
> +               year = tm->tm_year;
> +               if (year > 99)
> +                       year -= 100;
> +               ioport__write8(data, bin2bcd(year));
>                 break;
>         default:
>                 ioport__write8(data, rtc.cmos_data[rtc.cmos_idx]);
--
To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Stable Commits]     [Linux Stable Kernel]     [Linux Kernel]     [Linux USB Devel]     [Linux Video &Media]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux