From: Jordan Crouse <jordan.crouse@amd.com>
To: linux-acpi@vger.kernel.org
Subject: [PATCH] fix math in acpi_system_write_alarm() (resend)
Date: Fri, 26 Sep 2008 17:32:00 -0600 [thread overview]
Message-ID: <20080926233200.GB6061@cosmic.amd.com> (raw)
[-- 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;
next reply other threads:[~2008-09-26 23:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-26 23:32 Jordan Crouse [this message]
2008-09-27 2:10 ` [PATCH] fix math in acpi_system_write_alarm() (resend) Zhang Rui
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=20080926233200.GB6061@cosmic.amd.com \
--to=jordan.crouse@amd.com \
--cc=linux-acpi@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 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.