Skip to contentSkip to conversation

ACPI: Make sure that the alarm math is correct

PATCH New Jordan Crouse 1 participant 1 message Jul 10, 2008 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI: Make sure that the alarm math is correct

On June 30, we were running some suspend/resume cycles with an alarm time set through /proc/acpi/alarm. We discovered the next morning that all of the boxes were suspended. Investigation showed that they all had an alarm set for June 31.. :)

It turns out the /proc/acpi/alarm code assumes 31 days for all months. The attached patch does the correct math. I know this is a deprecated interface, but I figure that as long as the code is living in Linus's tree, it should be correct.

Jordan

Signature · 3 lines
Jordan Crouse
Systems Software Development Engineer 
Advanced Micro Devices, Inc.

[PATCH] ACPI: Make sure that the alarm math is correct

From: Jordan Crouse <[email protected]>

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.

---

 drivers/acpi/sleep/proc.c |   28 +++++++++++++++++++++++++---
 1 files changed, 25 insertions(+), 3 deletions(-)
drivers/acpi/sleep/proc.c +25 -3
index 4ebbba2..19c150b 100644
@@ -283,10 +283,32 @@ 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;