public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Linux ACPI <linux-acpi@vger.kernel.org>,
	linux-rtc@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v1 3/4] ACPI: TAD: RTC: Refine timer value computations and checks
Date: Thu, 23 Apr 2026 22:30:17 +0200	[thread overview]
Message-ID: <20260423203017d25ac200@mail.local> (raw)
In-Reply-To: <3414608.aeNJFYEL58@rafael.j.wysocki>

On 22/04/2026 17:26:49+0200, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Since rtc_tm_to_ktime() may overflow for large RTC time values and
> full second granularity is sufficient in timer value computations
> in acpi_tad_rtc_set_alarm() and acpi_tad_rtc_read_alarm(), use
> rtc_tm_to_time64() instead of that function, which also allows the
> computations to be simplified.
> 
> Moreover, U32_MAX is a special "timer disabled" value, so make
> acpi_tad_rtc_set_alarm() reject it when attempting to program the
> alarm timers.
> 
> Fixes: 7572dcabe38d ("ACPI: TAD: Add alarm support to the RTC class device interface")
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Reviewed-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

> ---
>  drivers/acpi/acpi_tad.c |    8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> --- a/drivers/acpi/acpi_tad.c
> +++ b/drivers/acpi/acpi_tad.c
> @@ -680,9 +680,8 @@ static int acpi_tad_rtc_set_alarm(struct
>  
>  		acpi_tad_rt_to_tm(&rt, &tm_now);
>  
> -		value = ktime_divns(ktime_sub(rtc_tm_to_ktime(t->time),
> -					      rtc_tm_to_ktime(tm_now)), NSEC_PER_SEC);
> -		if (value <= 0 || value > U32_MAX)
> +		value = rtc_tm_to_time64(&t->time) - rtc_tm_to_time64(&tm_now);
> +		if (value <= 0 || value >= U32_MAX)
>  			return -EINVAL;
>  	}
>  
> @@ -745,8 +744,7 @@ static int acpi_tad_rtc_read_alarm(struc
>  
>  	if (retval != ACPI_TAD_WAKE_DISABLED) {
>  		t->enabled = 1;
> -		t->time = rtc_ktime_to_tm(ktime_add_ns(rtc_tm_to_ktime(tm_now),
> -						       (u64)retval * NSEC_PER_SEC));
> +		rtc_time64_to_tm(rtc_tm_to_time64(&tm_now) + retval, &t->time);
>  	} else {
>  		t->enabled = 0;
>  		t->time = tm_now;
> 
> 
> 

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

  reply	other threads:[~2026-04-23 20:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-22 15:23 [PATCH v1 0/4] ACPI: TAD: Fixes and cleanups on top of recent changes Rafael J. Wysocki
2026-04-22 15:24 ` [PATCH v1 1/4] ACPI: TAD: Use __ATTRIBUTE_GROUPS() macro Rafael J. Wysocki
2026-04-22 15:25 ` [PATCH v1 2/4] ACPI: TAD: Use devres for all driver cleanup Rafael J. Wysocki
2026-04-22 15:26 ` [PATCH v1 3/4] ACPI: TAD: RTC: Refine timer value computations and checks Rafael J. Wysocki
2026-04-23 20:30   ` Alexandre Belloni [this message]
2026-04-22 15:27 ` [PATCH v1 4/4] ACPI: TAD: Fix up a comment in acpi_tad_probe() Rafael J. Wysocki

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=20260423203017d25ac200@mail.local \
    --to=alexandre.belloni@bootlin.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=rafael@kernel.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