oprofile: fixing whitespaces in drivers/oprofile/*
[linux-2.6.git] / drivers / oprofile / event_buffer.c
index 04d6417..d962ba0 100644 (file)
 #include <linux/dcookies.h>
 #include <linux/fs.h>
 #include <asm/uaccess.h>
+
 #include "oprof.h"
 #include "event_buffer.h"
 #include "oprofile_stats.h"
 
 DEFINE_MUTEX(buffer_mutex);
+
 static unsigned long buffer_opened;
 static DECLARE_WAIT_QUEUE_HEAD(buffer_wait);
-static unsigned long * event_buffer;
+static unsigned long *event_buffer;
 static unsigned long buffer_size;
 static unsigned long buffer_watershed;
 static size_t buffer_pos;
@@ -66,22 +66,23 @@ void wake_up_buffer_waiter(void)
        mutex_unlock(&buffer_mutex);
 }
 
+
 int alloc_event_buffer(void)
 {
        int err = -ENOMEM;
+       unsigned long flags;
 
-       spin_lock(&oprofilefs_lock);
+       spin_lock_irqsave(&oprofilefs_lock, flags);
        buffer_size = fs_buffer_size;
        buffer_watershed = fs_buffer_watershed;
-       spin_unlock(&oprofilefs_lock);
+       spin_unlock_irqrestore(&oprofilefs_lock, flags);
+
        if (buffer_watershed >= buffer_size)
                return -EINVAL;
+
        event_buffer = vmalloc(sizeof(unsigned long) * buffer_size);
        if (!event_buffer)
-               goto out; 
+               goto out;
 
        err = 0;
 out:
@@ -92,10 +93,12 @@ out:
 void free_event_buffer(void)
 {
        vfree(event_buffer);
+
+       event_buffer = NULL;
 }
 
-static int event_buffer_open(struct inode * inode, struct file * file)
+
+static int event_buffer_open(struct inode *inode, struct file *file)
 {
        int err = -EPERM;
 
@@ -113,14 +116,14 @@ static int event_buffer_open(struct inode * inode, struct file * file)
        file->private_data = dcookie_register();
        if (!file->private_data)
                goto out;
-                
+
        if ((err = oprofile_setup()))
                goto fail;
 
        /* NB: the actual start happens from userspace
         * echo 1 >/dev/oprofile/enable
         */
+
        return 0;
 
 fail:
@@ -131,7 +134,7 @@ out:
 }
 
 
-static int event_buffer_release(struct inode * inode, struct file * file)
+static int event_buffer_release(struct inode *inode, struct file *file)
 {
        oprofile_stop();
        oprofile_shutdown();
@@ -143,8 +146,8 @@ static int event_buffer_release(struct inode * inode, struct file * file)
 }
 
 
-static ssize_t event_buffer_read(struct file * file, char __user * buf,
-                                size_t count, loff_t * offset)
+static ssize_t event_buffer_read(struct file *file, char __user *buf,
+                                size_t count, loff_t *offset)
 {
        int retval = -EINVAL;
        size_t const max = buffer_size * sizeof(unsigned long);
@@ -169,19 +172,19 @@ static ssize_t event_buffer_read(struct file * file, char __user * buf,
        retval = -EFAULT;
 
        count = buffer_pos * sizeof(unsigned long);
+
        if (copy_to_user(buf, event_buffer, count))
                goto out;
 
        retval = count;
        buffer_pos = 0;
+
 out:
        mutex_unlock(&buffer_mutex);
        return retval;
 }
-struct file_operations event_buffer_fops = {
+
+const struct file_operations event_buffer_fops = {
        .open           = event_buffer_open,
        .release        = event_buffer_release,
        .read           = event_buffer_read,