linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Tang <danielzgtg.opensource@gmail.com>
To: linux-rtc@vger.kernel.org, systemd-devel@lists.freedesktop.org
Subject: Conflict between 1-indexed kernel struct rtc_time and 0-indexed userspace struct tm
Date: Mon, 25 Aug 2025 17:07:46 -0400	[thread overview]
Message-ID: <5818530.FO833rMHq7@daniel-desktop3> (raw)

Hello,

The difference seems undocumented and ignored by userspace. At https://
github.com/util-linux/util-linux/issues/3707 , we discussed the mismatch. My 
kernel module's assertion that a `rtc_time64_to_tm(rtc_tm_to_time64(tm), 
&tm_check)` will result in a bit-identical struct failed at tm_yday.

Userspace https://man7.org/linux/man-pages/man3/tm.3type.html documents a 0-
indexed int         tm_yday;   /* Day of the year  [0, 365] (Jan/01 = 0) */
The kernel struct rtc_time is uncommented, but https://github.com/torvalds/
linux/blob/b6add54ba61890450fa54fd9327d10fdfd653439/drivers/rtc/lib.c#L136 
intentionally adds 1 to make it 1-indexed, and this appears to have been 
consistent through git history. rtc-asm9260.c and rtc-lpc24xx.c read from 
tm_yday before writing to hardware, but it tm_yday may have been corrected by 
an overwrite by other parts of the rtc core. My kernel module validates 
tm_yday but doesn't use it, whereas it may be unknown whether other modules 
are expecting a 1-indexed or 0-indexed value.

I was about to suggest that userspace perform `tm_year++` before the ioctl, 
but then https://github.com/systemd/systemd/issues/
38715#issuecomment-3221685983 said:
>At least, rtc(4) states about struct rtc_time as
>>The fields in this structure have the same meaning and ranges as for the tm 
structure described in gmtime(3).
>I guess this is a kernel driver or firmware issue if it does not work.

What should be done to make the 0-indexing/1-indexing of tm_yday consistent 
between kernelspace and userspace?

Sincerely,
daniel . z . tg



                 reply	other threads:[~2025-08-25 21:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=5818530.FO833rMHq7@daniel-desktop3 \
    --to=danielzgtg.opensource@gmail.com \
    --cc=linux-rtc@vger.kernel.org \
    --cc=systemd-devel@lists.freedesktop.org \
    /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;
as well as URLs for NNTP newsgroup(s).