* [PATCH] fix math in acpi_system_write_alarm() (resend)
@ 2008-09-26 23:32 Jordan Crouse
2008-09-27 2:10 ` Zhang Rui
0 siblings, 1 reply; 2+ messages in thread
From: Jordan Crouse @ 2008-09-26 23:32 UTC (permalink / raw)
To: linux-acpi
[-- Attachment #1: Type: text/plain, Size: 481 bytes --]
This patch fixes the day of month math in acpi_system_write_alarm().
The previous code assumed that there were 31 days in every month.
We caught this on June 30 when the month changed, but the system
stayed suspended waiting for June 31st.
I know /proc/acpi/alarm is being deprecated, but its still there,
and I think as long as somebody can use it in anger, it should
correct.
Thanks,
Jordan
--
Jordan Crouse
Systems Software Development Engineer
Advanced Micro Devices, Inc.
[-- Attachment #2: fix-acpi-alarm.patch --]
[-- Type: text/x-diff, Size: 1185 bytes --]
[PATCH] ACPI: Make sure that the alarm math is correct
From: Jordan Crouse <jordan.crouse@amd.com>
The current /proc/acpi/alarm math assumes that every month has 31 days.
This patch figures out the correct number of days in the month.
Signed-off-by: Jordan Crouse <jordan.crouse@amd.com>
---
drivers/acpi/sleep/proc.c | 27 ++++++++++++++++++++++++---
1 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/drivers/acpi/sleep/proc.c b/drivers/acpi/sleep/proc.c
index 4ebbba2..0e75d79 100644
--- a/drivers/acpi/sleep/proc.c
+++ b/drivers/acpi/sleep/proc.c
@@ -283,10 +283,31 @@ acpi_system_write_alarm(struct file *file,
day += hr/24;
hr = hr%24;
}
- if (day > 31) {
- mo += day/32;
- day = day%32;
+
+ while (1) {
+ int tmo = mo % 13;
+ int dinmo;
+
+ if (tmo == 2) {
+ if (((yr % 4 == 0) && (yr % 100 != 0)) ||
+ (yr % 400 == 0))
+ dinmo = 29;
+ else
+ dinmo = 28;
+ } else if (tmo == 1 || tmo == 3 || tmo == 5 ||
+ tmo == 7 || tmo == 8 || tmo == 10 ||
+ tmo == 12)
+ dinmo = 31;
+ else
+ dinmo = 30;
+
+ if (day <= dinmo)
+ break;
+
+ mo += 1;
+ day -= dinmo;
}
+
if (mo > 12) {
yr += mo/13;
mo = mo%13;
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] fix math in acpi_system_write_alarm() (resend)
2008-09-26 23:32 [PATCH] fix math in acpi_system_write_alarm() (resend) Jordan Crouse
@ 2008-09-27 2:10 ` Zhang Rui
0 siblings, 0 replies; 2+ messages in thread
From: Zhang Rui @ 2008-09-27 2:10 UTC (permalink / raw)
To: Jordan Crouse; +Cc: linux-acpi@vger.kernel.org
On Fri, 2008-09-26 at 16:32 -0700, Jordan Crouse wrote:
> This patch fixes the day of month math in acpi_system_write_alarm().
> The previous code assumed that there were 31 days in every month.
> We caught this on June 30 when the month changed, but the system
> stayed suspended waiting for June 31st.
>
> I know /proc/acpi/alarm is being deprecated, but its still there,
> and I think as long as somebody can use it in anger, it should
> correct.
>
agree.
len, I think we should also apply this patch.
Subject: ACPI: deprecate /proc/acpi/alarm
/proc/acpi/alarm is deprecated.
users can use /sys/class/rtc/rtcX/wakealarm instead.
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
---
drivers/acpi/Kconfig | 1 +
drivers/acpi/sleep/proc.c | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
Index: linux-2.6/drivers/acpi/sleep/proc.c
===================================================================
--- linux-2.6.orig/drivers/acpi/sleep/proc.c
+++ linux-2.6/drivers/acpi/sleep/proc.c
@@ -78,7 +78,7 @@ acpi_system_write_sleep(struct file *fil
}
#endif /* CONFIG_ACPI_PROCFS */
-#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE) || !defined(CONFIG_X86)
+#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE) || !defined(CONFIG_X86) || !define(CONFIG_ACPI_PROCFS)
/* use /sys/class/rtc/rtcX/wakealarm instead; it's not ACPI-specific */
#else
#define HAVE_ACPI_LEGACY_ALARM
Index: linux-2.6/drivers/acpi/Kconfig
===================================================================
--- linux-2.6.orig/drivers/acpi/Kconfig
+++ linux-2.6/drivers/acpi/Kconfig
@@ -60,6 +60,7 @@ config ACPI_PROCFS
/proc/acpi/fadt (/sys/firmware/acpi/tables/FACP)
/proc/acpi/debug_layer (/sys/module/acpi/parameters/debug_layer)
/proc/acpi/debug_level (/sys/module/acpi/parameters/debug_level)
+ /proc/acpi/alarm (/sys/class/rtc/rtcX/wakealarm)
This option has no effect on /proc/acpi/ files
and functions which do not yet exist in /sys.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-09-27 2:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-26 23:32 [PATCH] fix math in acpi_system_write_alarm() (resend) Jordan Crouse
2008-09-27 2:10 ` Zhang Rui
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.