Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394...
[pandora-kernel.git] / drivers / char / apm-emulation.c
index c99e43b..da8a165 100644 (file)
@@ -13,7 +13,9 @@
 #include <linux/module.h>
 #include <linux/poll.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/proc_fs.h>
+#include <linux/seq_file.h>
 #include <linux/miscdevice.h>
 #include <linux/apm_bios.h>
 #include <linux/capability.h>
@@ -295,7 +297,6 @@ static int
 apm_ioctl(struct inode * inode, struct file *filp, u_int cmd, u_long arg)
 {
        struct apm_user *as = filp->private_data;
-       unsigned long flags;
        int err = -EINVAL;
 
        if (!as->suser || !as->writer)
@@ -331,10 +332,16 @@ apm_ioctl(struct inode * inode, struct file *filp, u_int cmd, u_long arg)
                         * Wait for the suspend/resume to complete.  If there
                         * are pending acknowledges, we wait here for them.
                         */
-                       flags = current->flags;
+                       freezer_do_not_count();
 
                        wait_event(apm_suspend_waitqueue,
                                   as->suspend_state == SUSPEND_DONE);
+
+                       /*
+                        * Since we are waiting until the suspend is done, the
+                        * try_to_freeze() in freezer_count() will not trigger
+                        */
+                       freezer_count();
                } else {
                        as->suspend_state = SUSPEND_WAIT;
                        mutex_unlock(&state_lock);
@@ -362,14 +369,10 @@ apm_ioctl(struct inode * inode, struct file *filp, u_int cmd, u_long arg)
                         * Wait for the suspend/resume to complete.  If there
                         * are pending acknowledges, we wait here for them.
                         */
-                       flags = current->flags;
-
-                       wait_event_interruptible(apm_suspend_waitqueue,
+                       wait_event_freezable(apm_suspend_waitqueue,
                                         as->suspend_state == SUSPEND_DONE);
                }
 
-               current->flags = flags;
-
                mutex_lock(&state_lock);
                err = as->suspend_result;
                as->suspend_state = SUSPEND_NONE;
@@ -414,6 +417,7 @@ static int apm_open(struct inode * inode, struct file * filp)
 {
        struct apm_user *as;
 
+       lock_kernel();
        as = kzalloc(sizeof(*as), GFP_KERNEL);
        if (as) {
                /*
@@ -433,6 +437,7 @@ static int apm_open(struct inode * inode, struct file * filp)
 
                filp->private_data = as;
        }
+       unlock_kernel();
 
        return as ? 0 : -ENOMEM;
 }
@@ -492,11 +497,10 @@ static struct miscdevice apm_device = {
  *     -1: Unknown
  *   8) min = minutes; sec = seconds
  */
-static int apm_get_info(char *buf, char **start, off_t fpos, int length)
+static int proc_apm_show(struct seq_file *m, void *v)
 {
        struct apm_power_info info;
        char *units;
-       int ret;
 
        info.ac_line_status = 0xff;
        info.battery_status = 0xff;
@@ -514,14 +518,27 @@ static int apm_get_info(char *buf, char **start, off_t fpos, int length)
        case 1:         units = "sec";  break;
        }
 
-       ret = sprintf(buf, "%s 1.2 0x%02x 0x%02x 0x%02x 0x%02x %d%% %d %s\n",
+       seq_printf(m, "%s 1.2 0x%02x 0x%02x 0x%02x 0x%02x %d%% %d %s\n",
                     driver_version, APM_32_BIT_SUPPORT,
                     info.ac_line_status, info.battery_status,
                     info.battery_flag, info.battery_life,
                     info.time, units);
 
-       return ret;
+       return 0;
+}
+
+static int proc_apm_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, proc_apm_show, NULL);
 }
+
+static const struct file_operations apm_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = proc_apm_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
 #endif
 
 static int kapmd(void *arg)
@@ -592,7 +609,7 @@ static int __init apm_init(void)
        wake_up_process(kapmd_tsk);
 
 #ifdef CONFIG_PROC_FS
-       create_proc_info_entry("apm", 0, NULL, apm_get_info);
+       proc_create("apm", 0, NULL, &apm_proc_fops);
 #endif
 
        ret = misc_register(&apm_device);