x86: coding style fixes to arch/x86/kernel/msr.c
[sfrench/cifs-2.6.git] / arch / x86 / kernel / msr.c
index c044de310b691901c05453c046fe48796d0d5182..4dfb4053005714bb222f19d821856ccb19cadd7a 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------- *
- *   
- *   Copyright 2000 H. Peter Anvin - All Rights Reserved
+ *
+ *   Copyright 2000-2008 H. Peter Anvin - All Rights Reserved
  *
  *   This program is free software; you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
@@ -45,9 +45,10 @@ static struct class *msr_class;
 
 static loff_t msr_seek(struct file *file, loff_t offset, int orig)
 {
-       loff_t ret = -EINVAL;
+       loff_t ret;
+       struct inode *inode = file->f_mapping->host;
 
-       lock_kernel();
+       mutex_lock(&inode->i_mutex);
        switch (orig) {
        case 0:
                file->f_pos = offset;
@@ -56,13 +57,16 @@ static loff_t msr_seek(struct file *file, loff_t offset, int orig)
        case 1:
                file->f_pos += offset;
                ret = file->f_pos;
+               break;
+       default:
+               ret = -EINVAL;
        }
-       unlock_kernel();
+       mutex_unlock(&inode->i_mutex);
        return ret;
 }
 
-static ssize_t msr_read(struct file *file, char __user * buf,
-                       size_t count, loff_t * ppos)
+static ssize_t msr_read(struct file *file, char __user *buf,
+                       size_t count, loff_t *ppos)
 {
        u32 __user *tmp = (u32 __user *) buf;
        u32 data[2];
@@ -112,7 +116,7 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
 static int msr_open(struct inode *inode, struct file *file)
 {
        unsigned int cpu = iminor(file->f_path.dentry->d_inode);
-       struct cpuinfo_x86 *c = &(cpu_data)[cpu];
+       struct cpuinfo_x86 *c = &cpu_data(cpu);
 
        if (cpu >= NR_CPUS || !cpu_online(cpu))
                return -ENXIO;  /* No such CPU */
@@ -133,37 +137,42 @@ static const struct file_operations msr_fops = {
        .open = msr_open,
 };
 
-static int msr_device_create(int i)
+static int __cpuinit msr_device_create(int cpu)
 {
-       int err = 0;
        struct device *dev;
 
-       dev = device_create(msr_class, NULL, MKDEV(MSR_MAJOR, i), "msr%d",i);
-       if (IS_ERR(dev))
-               err = PTR_ERR(dev);
-       return err;
+       dev = device_create(msr_class, NULL, MKDEV(MSR_MAJOR, cpu),
+                           "msr%d", cpu);
+       return IS_ERR(dev) ? PTR_ERR(dev) : 0;
+}
+
+static void msr_device_destroy(int cpu)
+{
+       device_destroy(msr_class, MKDEV(MSR_MAJOR, cpu));
 }
 
-static int msr_class_cpu_callback(struct notifier_block *nfb,
+static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
                                unsigned long action, void *hcpu)
 {
        unsigned int cpu = (unsigned long)hcpu;
+       int err = 0;
 
        switch (action) {
-       case CPU_ONLINE:
-       case CPU_ONLINE_FROZEN:
-               msr_device_create(cpu);
+       case CPU_UP_PREPARE:
+               err = msr_device_create(cpu);
                break;
+       case CPU_UP_CANCELED:
        case CPU_DEAD:
-       case CPU_DEAD_FROZEN:
-               device_destroy(msr_class, MKDEV(MSR_MAJOR, cpu));
+               msr_device_destroy(cpu);
+               break;
+       case CPU_UP_CANCELED_FROZEN:
+               destroy_suspended_device(msr_class, MKDEV(MSR_MAJOR, cpu));
                break;
        }
-       return NOTIFY_OK;
+       return err ? NOTIFY_BAD : NOTIFY_OK;
 }
 
-static struct notifier_block __cpuinitdata msr_class_cpu_notifier =
-{
+static struct notifier_block __refdata msr_class_cpu_notifier = {
        .notifier_call = msr_class_cpu_callback,
 };
 
@@ -196,7 +205,7 @@ static int __init msr_init(void)
 out_class:
        i = 0;
        for_each_online_cpu(i)
-               device_destroy(msr_class, MKDEV(MSR_MAJOR, i));
+               msr_device_destroy(i);
        class_destroy(msr_class);
 out_chrdev:
        unregister_chrdev(MSR_MAJOR, "cpu/msr");
@@ -208,7 +217,7 @@ static void __exit msr_exit(void)
 {
        int cpu = 0;
        for_each_online_cpu(cpu)
-               device_destroy(msr_class, MKDEV(MSR_MAJOR, cpu));
+               msr_device_destroy(cpu);
        class_destroy(msr_class);
        unregister_chrdev(MSR_MAJOR, "cpu/msr");
        unregister_hotcpu_notifier(&msr_class_cpu_notifier);