* [PATCH 1/1] rtc: add century field data boundary
@ 2016-10-04 18:06 Andrew Kim
2016-10-05 7:03 ` Geert Uytterhoeven
0 siblings, 1 reply; 4+ messages in thread
From: Andrew Kim @ 2016-10-04 18:06 UTC (permalink / raw)
To: linux-kernel
According to ACPI specification, the century field data
should be ranged 0-63. so if it's over this range, it could
cause system RTC settings error including alarmwakeup settings.
So it's required to have this boundary for safe RTC init settings.
Signed-off-by: Andrew Kim <andrew.kim@intel.com>
---
arch/x86/kernel/rtc.c | 7 +++++--
drivers/rtc/rtc-mc146818-lib.c | 7 +++++--
include/linux/mc146818rtc.h | 2 ++
3 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kernel/rtc.c b/arch/x86/kernel/rtc.c
index 79c6311c..feac180 100644
--- a/arch/x86/kernel/rtc.c
+++ b/arch/x86/kernel/rtc.c
@@ -84,8 +84,11 @@ void mach_get_cmos_time(struct timespec *now)
#ifdef CONFIG_ACPI
if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID &&
- acpi_gbl_FADT.century)
- century = CMOS_READ(acpi_gbl_FADT.century);
+ acpi_gbl_FADT.century) {
+ if ((century = CMOS_READ(acpi_gbl_FADT.century)) >
+ RTC_CENTURY_LIMIT)
+ century = 0;
+ }
#endif
status = CMOS_READ(RTC_CONTROL);
diff --git a/drivers/rtc/rtc-mc146818-lib.c b/drivers/rtc/rtc-mc146818-lib.c
index 2f1772a..1d83c2c 100644
--- a/drivers/rtc/rtc-mc146818-lib.c
+++ b/drivers/rtc/rtc-mc146818-lib.c
@@ -61,8 +61,11 @@ unsigned int mc146818_get_time(struct rtc_time *time)
#endif
#ifdef CONFIG_ACPI
if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID &&
- acpi_gbl_FADT.century)
- century = CMOS_READ(acpi_gbl_FADT.century);
+ acpi_gbl_FADT.century) {
+ if ((century = CMOS_READ(acpi_gbl_FADT.century)) >
+ RTC_CENTURY_LIMIT)
+ century = 0;
+ }
#endif
ctrl = CMOS_READ(RTC_CONTROL);
spin_unlock_irqrestore(&rtc_lock, flags);
diff --git a/include/linux/mc146818rtc.h b/include/linux/mc146818rtc.h
index a585b4b..199065a 100644
--- a/include/linux/mc146818rtc.h
+++ b/include/linux/mc146818rtc.h
@@ -122,6 +122,8 @@ struct cmos_rtc_board_info {
#define RTC_IO_EXTENT_USED RTC_IO_EXTENT
#endif /* ARCH_RTC_LOCATION */
+#define RTC_CENTURY_LIMIT 0x3F
+
unsigned int mc146818_get_time(struct rtc_time *time);
int mc146818_set_time(struct rtc_time *time);
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] rtc: add century field data boundary
2016-10-04 18:06 [PATCH 1/1] rtc: add century field data boundary Andrew Kim
@ 2016-10-05 7:03 ` Geert Uytterhoeven
2016-10-05 17:32 ` Kim, Andrew
0 siblings, 1 reply; 4+ messages in thread
From: Geert Uytterhoeven @ 2016-10-05 7:03 UTC (permalink / raw)
To: Andrew Kim; +Cc: linux-kernel
On Tue, Oct 4, 2016 at 8:06 PM, Andrew Kim <andrew.kim@intel.com> wrote:
> According to ACPI specification, the century field data
> should be ranged 0-63. so if it's over this range, it could
> cause system RTC settings error including alarmwakeup settings.
> So it's required to have this boundary for safe RTC init settings.
>
> Signed-off-by: Andrew Kim <andrew.kim@intel.com>
> ---
> arch/x86/kernel/rtc.c | 7 +++++--
> drivers/rtc/rtc-mc146818-lib.c | 7 +++++--
> include/linux/mc146818rtc.h | 2 ++
> 3 files changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/kernel/rtc.c b/arch/x86/kernel/rtc.c
> index 79c6311c..feac180 100644
> --- a/arch/x86/kernel/rtc.c
> +++ b/arch/x86/kernel/rtc.c
> @@ -84,8 +84,11 @@ void mach_get_cmos_time(struct timespec *now)
>
> #ifdef CONFIG_ACPI
> if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID &&
> - acpi_gbl_FADT.century)
> - century = CMOS_READ(acpi_gbl_FADT.century);
> + acpi_gbl_FADT.century) {
> + if ((century = CMOS_READ(acpi_gbl_FADT.century)) >
> + RTC_CENTURY_LIMIT)
Please don't combine assignments and comparisons into a single statement
(especially for non-NULL comparisons), i.e. use
century = CMOS_READ(acpi_gbl_FADT.century);
if (century > RTC_CENTURY_LIMIT) {
...
> + century = 0;
> + }
> #endif
>
> status = CMOS_READ(RTC_CONTROL);
> diff --git a/drivers/rtc/rtc-mc146818-lib.c b/drivers/rtc/rtc-mc146818-lib.c
> index 2f1772a..1d83c2c 100644
> --- a/drivers/rtc/rtc-mc146818-lib.c
> +++ b/drivers/rtc/rtc-mc146818-lib.c
> @@ -61,8 +61,11 @@ unsigned int mc146818_get_time(struct rtc_time *time)
> #endif
> #ifdef CONFIG_ACPI
> if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID &&
> - acpi_gbl_FADT.century)
> - century = CMOS_READ(acpi_gbl_FADT.century);
> + acpi_gbl_FADT.century) {
> + if ((century = CMOS_READ(acpi_gbl_FADT.century)) >
> + RTC_CENTURY_LIMIT)
Likewise
> + century = 0;
> + }
> #endif
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH 1/1] rtc: add century field data boundary
2016-10-05 7:03 ` Geert Uytterhoeven
@ 2016-10-05 17:32 ` Kim, Andrew
0 siblings, 0 replies; 4+ messages in thread
From: Kim, Andrew @ 2016-10-05 17:32 UTC (permalink / raw)
To: Geert Uytterhoeven; +Cc: linux-kernel
Thanks for the comments, let me follow this.
BRs
Andrew
-----Original Message-----
From: geert.uytterhoeven@gmail.com [mailto:geert.uytterhoeven@gmail.com] On Behalf Of Geert Uytterhoeven
Sent: Wednesday, October 05, 2016 12:03 AM
To: Kim, Andrew
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] rtc: add century field data boundary
On Tue, Oct 4, 2016 at 8:06 PM, Andrew Kim <andrew.kim@intel.com> wrote:
> According to ACPI specification, the century field data should be
> ranged 0-63. so if it's over this range, it could cause system RTC
> settings error including alarmwakeup settings.
> So it's required to have this boundary for safe RTC init settings.
>
> Signed-off-by: Andrew Kim <andrew.kim@intel.com>
> ---
> arch/x86/kernel/rtc.c | 7 +++++--
> drivers/rtc/rtc-mc146818-lib.c | 7 +++++--
> include/linux/mc146818rtc.h | 2 ++
> 3 files changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/kernel/rtc.c b/arch/x86/kernel/rtc.c index
> 79c6311c..feac180 100644
> --- a/arch/x86/kernel/rtc.c
> +++ b/arch/x86/kernel/rtc.c
> @@ -84,8 +84,11 @@ void mach_get_cmos_time(struct timespec *now)
>
> #ifdef CONFIG_ACPI
> if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID &&
> - acpi_gbl_FADT.century)
> - century = CMOS_READ(acpi_gbl_FADT.century);
> + acpi_gbl_FADT.century) {
> + if ((century = CMOS_READ(acpi_gbl_FADT.century)) >
> + RTC_CENTURY_LIMIT)
Please don't combine assignments and comparisons into a single statement (especially for non-NULL comparisons), i.e. use
century = CMOS_READ(acpi_gbl_FADT.century);
if (century > RTC_CENTURY_LIMIT) {
...
> + century = 0;
> + }
> #endif
>
> status = CMOS_READ(RTC_CONTROL); diff --git
> a/drivers/rtc/rtc-mc146818-lib.c b/drivers/rtc/rtc-mc146818-lib.c
> index 2f1772a..1d83c2c 100644
> --- a/drivers/rtc/rtc-mc146818-lib.c
> +++ b/drivers/rtc/rtc-mc146818-lib.c
> @@ -61,8 +61,11 @@ unsigned int mc146818_get_time(struct rtc_time
> *time) #endif #ifdef CONFIG_ACPI
> if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID &&
> - acpi_gbl_FADT.century)
> - century = CMOS_READ(acpi_gbl_FADT.century);
> + acpi_gbl_FADT.century) {
> + if ((century = CMOS_READ(acpi_gbl_FADT.century)) >
> + RTC_CENTURY_LIMIT)
Likewise
> + century = 0;
> + }
> #endif
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/1] rtc: add century field data boundary
@ 2016-10-05 18:48 Andrew Kim
0 siblings, 0 replies; 4+ messages in thread
From: Andrew Kim @ 2016-10-05 18:48 UTC (permalink / raw)
To: linux-kernel
According to ACPI specification, the century field data
should be ranged 0-63. so if it's over this range, it could
cause system RTC settings error including alarmwakeup settings.
So it's required to have this boundary for safe RTC init settings.
Signed-off-by: Andrew Kim <andrew.kim@intel.com>
---
arch/x86/kernel/rtc.c | 5 ++++-
drivers/rtc/rtc-mc146818-lib.c | 5 ++++-
include/linux/mc146818rtc.h | 2 ++
3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/rtc.c b/arch/x86/kernel/rtc.c
index 79c6311c..795a9ab 100644
--- a/arch/x86/kernel/rtc.c
+++ b/arch/x86/kernel/rtc.c
@@ -84,8 +84,11 @@ void mach_get_cmos_time(struct timespec *now)
#ifdef CONFIG_ACPI
if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID &&
- acpi_gbl_FADT.century)
+ acpi_gbl_FADT.century) {
century = CMOS_READ(acpi_gbl_FADT.century);
+ if (century > RTC_CENTURY_LIMIT)
+ century = 0;
+ }
#endif
status = CMOS_READ(RTC_CONTROL);
diff --git a/drivers/rtc/rtc-mc146818-lib.c b/drivers/rtc/rtc-mc146818-lib.c
index 2f1772a..81eb2a2 100644
--- a/drivers/rtc/rtc-mc146818-lib.c
+++ b/drivers/rtc/rtc-mc146818-lib.c
@@ -61,8 +61,11 @@ unsigned int mc146818_get_time(struct rtc_time *time)
#endif
#ifdef CONFIG_ACPI
if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID &&
- acpi_gbl_FADT.century)
+ acpi_gbl_FADT.century) {
century = CMOS_READ(acpi_gbl_FADT.century);
+ if (century > RTC_CENTURY_LIMIT)
+ century = 0;
+ }
#endif
ctrl = CMOS_READ(RTC_CONTROL);
spin_unlock_irqrestore(&rtc_lock, flags);
diff --git a/include/linux/mc146818rtc.h b/include/linux/mc146818rtc.h
index a585b4b..199065a 100644
--- a/include/linux/mc146818rtc.h
+++ b/include/linux/mc146818rtc.h
@@ -122,6 +122,8 @@ struct cmos_rtc_board_info {
#define RTC_IO_EXTENT_USED RTC_IO_EXTENT
#endif /* ARCH_RTC_LOCATION */
+#define RTC_CENTURY_LIMIT 0x3F
+
unsigned int mc146818_get_time(struct rtc_time *time);
int mc146818_set_time(struct rtc_time *time);
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-10-05 18:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-04 18:06 [PATCH 1/1] rtc: add century field data boundary Andrew Kim
2016-10-05 7:03 ` Geert Uytterhoeven
2016-10-05 17:32 ` Kim, Andrew
2016-10-05 18:48 Andrew Kim
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).