]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/acpi/sleep/proc.c
acpi: use non-racy method for proc entries creation
[mirror_ubuntu-bionic-kernel.git] / drivers / acpi / sleep / proc.c
index 1538355c266b4a5a26bf12d31424b7d0e1563127..8a5fe87105139c5529119bfc69b84d349d2cf1e7 100644 (file)
@@ -178,6 +178,9 @@ static int get_date_field(char **p, u32 * value)
         * Try to find delimeter, only to insert null.  The end of the
         * string won't have one, but is still valid.
         */
+       if (*p == NULL)
+               return result;
+
        next = strpbrk(*p, "- :");
        if (next)
                *next++ = '\0';
@@ -190,6 +193,8 @@ static int get_date_field(char **p, u32 * value)
 
        if (next)
                *p = next;
+       else
+               *p = NULL;
 
        return result;
 }
@@ -251,27 +256,6 @@ acpi_system_write_alarm(struct file *file,
        if ((result = get_date_field(&p, &sec)))
                goto end;
 
-       if (sec > 59) {
-               min += 1;
-               sec -= 60;
-       }
-       if (min > 59) {
-               hr += 1;
-               min -= 60;
-       }
-       if (hr > 23) {
-               day += 1;
-               hr -= 24;
-       }
-       if (day > 31) {
-               mo += 1;
-               day -= 31;
-       }
-       if (mo > 12) {
-               yr += 1;
-               mo -= 12;
-       }
-
        spin_lock_irq(&rtc_lock);
 
        rtc_control = CMOS_READ(RTC_CONTROL);
@@ -288,24 +272,24 @@ acpi_system_write_alarm(struct file *file,
        spin_unlock_irq(&rtc_lock);
 
        if (sec > 59) {
-               min++;
-               sec -= 60;
+               min += sec/60;
+               sec = sec%60;
        }
        if (min > 59) {
-               hr++;
-               min -= 60;
+               hr += min/60;
+               min = min%60;
        }
        if (hr > 23) {
-               day++;
-               hr -= 24;
+               day += hr/24;
+               hr = hr%24;
        }
        if (day > 31) {
-               mo++;
-               day -= 31;
+               mo += day/32;
+               day = day%32;
        }
        if (mo > 12) {
-               yr++;
-               mo -= 12;
+               yr += mo/13;
+               mo = mo%13;
        }
 
        spin_lock_irq(&rtc_lock);
@@ -456,6 +440,7 @@ acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file)
 }
 
 static const struct file_operations acpi_system_wakeup_device_fops = {
+       .owner = THIS_MODULE,
        .open = acpi_system_wakeup_device_open_fs,
        .read = seq_read,
        .write = acpi_system_write_wakeup_device,
@@ -465,6 +450,7 @@ static const struct file_operations acpi_system_wakeup_device_fops = {
 
 #ifdef CONFIG_ACPI_PROCFS
 static const struct file_operations acpi_system_sleep_fops = {
+       .owner = THIS_MODULE,
        .open = acpi_system_sleep_open_fs,
        .read = seq_read,
        .write = acpi_system_write_sleep,
@@ -475,6 +461,7 @@ static const struct file_operations acpi_system_sleep_fops = {
 
 #ifdef HAVE_ACPI_LEGACY_ALARM
 static const struct file_operations acpi_system_alarm_fops = {
+       .owner = THIS_MODULE,
        .open = acpi_system_alarm_open_fs,
        .read = seq_read,
        .write = acpi_system_write_alarm,
@@ -493,37 +480,26 @@ static u32 rtc_handler(void *context)
 
 static int __init acpi_sleep_proc_init(void)
 {
-       struct proc_dir_entry *entry = NULL;
-
        if (acpi_disabled)
                return 0;
 
 #ifdef CONFIG_ACPI_PROCFS
        /* 'sleep' [R/W] */
-       entry =
-           create_proc_entry("sleep", S_IFREG | S_IRUGO | S_IWUSR,
-                             acpi_root_dir);
-       if (entry)
-               entry->proc_fops = &acpi_system_sleep_fops;
+       proc_create("sleep", S_IFREG | S_IRUGO | S_IWUSR,
+                   acpi_root_dir, &acpi_system_sleep_fops);
 #endif                         /* CONFIG_ACPI_PROCFS */
 
 #ifdef HAVE_ACPI_LEGACY_ALARM
        /* 'alarm' [R/W] */
-       entry =
-           create_proc_entry("alarm", S_IFREG | S_IRUGO | S_IWUSR,
-                             acpi_root_dir);
-       if (entry)
-               entry->proc_fops = &acpi_system_alarm_fops;
+       proc_create("alarm", S_IFREG | S_IRUGO | S_IWUSR,
+                   acpi_root_dir, &acpi_system_alarm_fops);
 
        acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, NULL);
 #endif                         /* HAVE_ACPI_LEGACY_ALARM */
 
        /* 'wakeup device' [R/W] */
-       entry =
-           create_proc_entry("wakeup", S_IFREG | S_IRUGO | S_IWUSR,
-                             acpi_root_dir);
-       if (entry)
-               entry->proc_fops = &acpi_system_wakeup_device_fops;
+       proc_create("wakeup", S_IFREG | S_IRUGO | S_IWUSR,
+                   acpi_root_dir, &acpi_system_wakeup_device_fops);
 
        return 0;
 }