[PATCH] fix math in acpi_system_write_alarm() (resend)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.
[PATCH] ACPI: Make sure that the alarm math is correct

From: Jordan Crouse <jordan.crouse@xxxxxxx>

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@xxxxxxx>
---

 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;

[Index of Archives]     [Linux IBM ACPI]     [Linux Power Management]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux