From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Linux ACPI <linux-acpi@vger.kernel.org>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>,
LKML <linux-kernel@vger.kernel.org>,
linux-rtc@vger.kernel.org, Linux PM <linux-pm@vger.kernel.org>
Subject: [PATCH v1 4/7] ACPI: TAD: Rearrange RT data validation checking
Date: Wed, 04 Mar 2026 19:14:44 +0100 [thread overview]
Message-ID: <3409319.aeNJFYEL58@rafael.j.wysocki> (raw)
In-Reply-To: <5092662.31r3eYUQgx@rafael.j.wysocki>
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Move RT data validation checks from acpi_tad_set_real_time() to
a separate function called acpi_tad_rt_is_invalid() and use it
also in acpi_tad_get_real_time() to validate data coming from
the platform firmware.
Also make acpi_tad_set_real_time() return -EINVAL when the RT data
passed to it is invalid (instead of -ERANGE which is somewhat
confusing) and introduce ACPI_TAD_TZ_UNSPEC to represent the
"unspecified timezone" value.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/acpi_tad.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
--- a/drivers/acpi/acpi_tad.c
+++ b/drivers/acpi/acpi_tad.c
@@ -49,6 +49,9 @@ MODULE_AUTHOR("Rafael J. Wysocki");
/* Special value for disabled timer or expired timer wake policy. */
#define ACPI_TAD_WAKE_DISABLED (~(u32)0)
+/* ACPI TAD RTC */
+#define ACPI_TAD_TZ_UNSPEC 2047
+
struct acpi_tad_driver_data {
u32 capabilities;
};
@@ -67,6 +70,16 @@ struct acpi_tad_rt {
u8 padding[3]; /* must be 0 */
} __packed;
+static bool acpi_tad_rt_is_invalid(struct acpi_tad_rt *rt)
+{
+ return rt->year < 1900 || rt->year > 9999 ||
+ rt->month < 1 || rt->month > 12 ||
+ rt->hour > 23 || rt->minute > 59 || rt->second > 59 ||
+ rt->tz < -1440 ||
+ (rt->tz > 1440 && rt->tz != ACPI_TAD_TZ_UNSPEC) ||
+ rt->daylight > 3;
+}
+
static int acpi_tad_set_real_time(struct device *dev, struct acpi_tad_rt *rt)
{
acpi_handle handle = ACPI_HANDLE(dev);
@@ -80,12 +93,8 @@ static int acpi_tad_set_real_time(struct
unsigned long long retval;
acpi_status status;
- if (rt->year < 1900 || rt->year > 9999 ||
- rt->month < 1 || rt->month > 12 ||
- rt->hour > 23 || rt->minute > 59 || rt->second > 59 ||
- rt->tz < -1440 || (rt->tz > 1440 && rt->tz != 2047) ||
- rt->daylight > 3)
- return -ERANGE;
+ if (acpi_tad_rt_is_invalid(rt))
+ return -EINVAL;
args[0].buffer.pointer = (u8 *)rt;
args[0].buffer.length = sizeof(*rt);
@@ -145,6 +154,9 @@ static int acpi_tad_get_real_time(struct
if (ret)
return ret;
+ if (acpi_tad_rt_is_invalid(rt))
+ return -ENODATA;
+
return 0;
}
next prev parent reply other threads:[~2026-03-04 18:17 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-04 18:11 [PATCH v1 0/7] ACPI: TAD: Assorted improvements and RTC class device interface Rafael J. Wysocki
2026-03-04 18:12 ` [PATCH v1 1/7] ACPI: TAD: Create one attribute group Rafael J. Wysocki
2026-03-04 18:13 ` [PATCH v1 2/7] ACPI: TAD: Support RTC without wakeup Rafael J. Wysocki
2026-03-04 18:14 ` [PATCH v1 3/7] ACPI: TAD: Use __free() for cleanup in time_store() Rafael J. Wysocki
2026-03-04 18:14 ` Rafael J. Wysocki [this message]
2026-03-04 18:15 ` [PATCH v1 5/7] ACPI: TAD: Clear unused RT data in acpi_tad_set_real_time() Rafael J. Wysocki
2026-03-04 18:16 ` [PATCH v1 6/7] ACPI: TAD: Add RTC class device interface Rafael J. Wysocki
2026-03-05 7:48 ` Alexandre Belloni
2026-03-04 18:16 ` [PATCH v1 7/7] ACPI: TAD: Update the driver description comment 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=3409319.aeNJFYEL58@rafael.j.wysocki \
--to=rafael@kernel.org \
--cc=alexandre.belloni@bootlin.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-rtc@vger.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