Skip to content

Commit 3329a14

Browse files
committed
ACPI: TAD: Rearrange RT data validation checking
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> Link: https://patch.msgid.link/3409319.aeNJFYEL58@rafael.j.wysocki
1 parent e64ab3e commit 3329a14

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

drivers/acpi/acpi_tad.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ MODULE_AUTHOR("Rafael J. Wysocki");
4949
/* Special value for disabled timer or expired timer wake policy. */
5050
#define ACPI_TAD_WAKE_DISABLED (~(u32)0)
5151

52+
/* ACPI TAD RTC */
53+
#define ACPI_TAD_TZ_UNSPEC 2047
54+
5255
struct acpi_tad_driver_data {
5356
u32 capabilities;
5457
};
@@ -67,6 +70,16 @@ struct acpi_tad_rt {
6770
u8 padding[3]; /* must be 0 */
6871
} __packed;
6972

73+
static bool acpi_tad_rt_is_invalid(struct acpi_tad_rt *rt)
74+
{
75+
return rt->year < 1900 || rt->year > 9999 ||
76+
rt->month < 1 || rt->month > 12 ||
77+
rt->hour > 23 || rt->minute > 59 || rt->second > 59 ||
78+
rt->tz < -1440 ||
79+
(rt->tz > 1440 && rt->tz != ACPI_TAD_TZ_UNSPEC) ||
80+
rt->daylight > 3;
81+
}
82+
7083
static int acpi_tad_set_real_time(struct device *dev, struct acpi_tad_rt *rt)
7184
{
7285
acpi_handle handle = ACPI_HANDLE(dev);
@@ -80,12 +93,8 @@ static int acpi_tad_set_real_time(struct device *dev, struct acpi_tad_rt *rt)
8093
unsigned long long retval;
8194
acpi_status status;
8295

83-
if (rt->year < 1900 || rt->year > 9999 ||
84-
rt->month < 1 || rt->month > 12 ||
85-
rt->hour > 23 || rt->minute > 59 || rt->second > 59 ||
86-
rt->tz < -1440 || (rt->tz > 1440 && rt->tz != 2047) ||
87-
rt->daylight > 3)
88-
return -ERANGE;
96+
if (acpi_tad_rt_is_invalid(rt))
97+
return -EINVAL;
8998

9099
args[0].buffer.pointer = (u8 *)rt;
91100
args[0].buffer.length = sizeof(*rt);
@@ -145,6 +154,9 @@ static int acpi_tad_get_real_time(struct device *dev, struct acpi_tad_rt *rt)
145154
if (ret)
146155
return ret;
147156

157+
if (acpi_tad_rt_is_invalid(rt))
158+
return -ENODATA;
159+
148160
return 0;
149161
}
150162

0 commit comments

Comments
 (0)