sysfs: Remove sysfs_get/put_active_two
[safe/jmp/linux-2.6] / fs / sysfs / bin.c
index 07703d3..e9d2935 100644 (file)
@@ -40,7 +40,7 @@ struct bin_buffer {
        struct mutex                    mutex;
        void                            *buffer;
        int                             mmapped;
-       struct vm_operations_struct     *vm_ops;
+       const struct vm_operations_struct *vm_ops;
        struct file                     *file;
        struct hlist_node               list;
 };
@@ -54,14 +54,14 @@ fill_read(struct dentry *dentry, char *buffer, loff_t off, size_t count)
        int rc;
 
        /* need attr_sd for attr, its parent for kobj */
-       if (!sysfs_get_active_two(attr_sd))
+       if (!sysfs_get_active(attr_sd))
                return -ENODEV;
 
        rc = -EIO;
        if (attr->read)
                rc = attr->read(kobj, attr, buffer, off, count);
 
-       sysfs_put_active_two(attr_sd);
+       sysfs_put_active(attr_sd);
 
        return rc;
 }
@@ -125,14 +125,14 @@ flush_write(struct dentry *dentry, char *buffer, loff_t offset, size_t count)
        int rc;
 
        /* need attr_sd for attr, its parent for kobj */
-       if (!sysfs_get_active_two(attr_sd))
+       if (!sysfs_get_active(attr_sd))
                return -ENODEV;
 
        rc = -EIO;
        if (attr->write)
                rc = attr->write(kobj, attr, buffer, offset, count);
 
-       sysfs_put_active_two(attr_sd);
+       sysfs_put_active(attr_sd);
 
        return rc;
 }
@@ -157,14 +157,9 @@ static ssize_t write(struct file *file, const char __user *userbuf,
                        count = size - offs;
        }
 
-       temp = kmalloc(count, GFP_KERNEL);
-       if (!temp)
-               return -ENOMEM;
-
-       if (copy_from_user(temp, userbuf, count)) {
-               count = -EFAULT;
-               goto out_free;
-       }
+       temp = memdup_user(userbuf, count);
+       if (IS_ERR(temp))
+               return PTR_ERR(temp);
 
        mutex_lock(&bb->mutex);
 
@@ -176,7 +171,6 @@ static ssize_t write(struct file *file, const char __user *userbuf,
        if (count > 0)
                *off = offs + count;
 
-out_free:
        kfree(temp);
        return count;
 }
@@ -190,12 +184,12 @@ static void bin_vma_open(struct vm_area_struct *vma)
        if (!bb->vm_ops || !bb->vm_ops->open)
                return;
 
-       if (!sysfs_get_active_two(attr_sd))
+       if (!sysfs_get_active(attr_sd))
                return;
 
        bb->vm_ops->open(vma);
 
-       sysfs_put_active_two(attr_sd);
+       sysfs_put_active(attr_sd);
 }
 
 static void bin_vma_close(struct vm_area_struct *vma)
@@ -207,12 +201,12 @@ static void bin_vma_close(struct vm_area_struct *vma)
        if (!bb->vm_ops || !bb->vm_ops->close)
                return;
 
-       if (!sysfs_get_active_two(attr_sd))
+       if (!sysfs_get_active(attr_sd))
                return;
 
        bb->vm_ops->close(vma);
 
-       sysfs_put_active_two(attr_sd);
+       sysfs_put_active(attr_sd);
 }
 
 static int bin_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
@@ -225,16 +219,16 @@ static int bin_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
        if (!bb->vm_ops || !bb->vm_ops->fault)
                return VM_FAULT_SIGBUS;
 
-       if (!sysfs_get_active_two(attr_sd))
+       if (!sysfs_get_active(attr_sd))
                return VM_FAULT_SIGBUS;
 
        ret = bb->vm_ops->fault(vma, vmf);
 
-       sysfs_put_active_two(attr_sd);
+       sysfs_put_active(attr_sd);
        return ret;
 }
 
-static int bin_page_mkwrite(struct vm_area_struct *vma, struct page *page)
+static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
        struct file *file = vma->vm_file;
        struct bin_buffer *bb = file->private_data;
@@ -242,17 +236,17 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct page *page)
        int ret;
 
        if (!bb->vm_ops)
-               return -EINVAL;
+               return VM_FAULT_SIGBUS;
 
        if (!bb->vm_ops->page_mkwrite)
                return 0;
 
-       if (!sysfs_get_active_two(attr_sd))
-               return -EINVAL;
+       if (!sysfs_get_active(attr_sd))
+               return VM_FAULT_SIGBUS;
 
-       ret = bb->vm_ops->page_mkwrite(vma, page);
+       ret = bb->vm_ops->page_mkwrite(vma, vmf);
 
-       sysfs_put_active_two(attr_sd);
+       sysfs_put_active(attr_sd);
        return ret;
 }
 
@@ -267,12 +261,12 @@ static int bin_access(struct vm_area_struct *vma, unsigned long addr,
        if (!bb->vm_ops || !bb->vm_ops->access)
                return -EINVAL;
 
-       if (!sysfs_get_active_two(attr_sd))
+       if (!sysfs_get_active(attr_sd))
                return -EINVAL;
 
        ret = bb->vm_ops->access(vma, addr, buf, len, write);
 
-       sysfs_put_active_two(attr_sd);
+       sysfs_put_active(attr_sd);
        return ret;
 }
 
@@ -287,12 +281,12 @@ static int bin_set_policy(struct vm_area_struct *vma, struct mempolicy *new)
        if (!bb->vm_ops || !bb->vm_ops->set_policy)
                return 0;
 
-       if (!sysfs_get_active_two(attr_sd))
+       if (!sysfs_get_active(attr_sd))
                return -EINVAL;
 
        ret = bb->vm_ops->set_policy(vma, new);
 
-       sysfs_put_active_two(attr_sd);
+       sysfs_put_active(attr_sd);
        return ret;
 }
 
@@ -307,12 +301,12 @@ static struct mempolicy *bin_get_policy(struct vm_area_struct *vma,
        if (!bb->vm_ops || !bb->vm_ops->get_policy)
                return vma->vm_policy;
 
-       if (!sysfs_get_active_two(attr_sd))
+       if (!sysfs_get_active(attr_sd))
                return vma->vm_policy;
 
        pol = bb->vm_ops->get_policy(vma, addr);
 
-       sysfs_put_active_two(attr_sd);
+       sysfs_put_active(attr_sd);
        return pol;
 }
 
@@ -327,17 +321,17 @@ static int bin_migrate(struct vm_area_struct *vma, const nodemask_t *from,
        if (!bb->vm_ops || !bb->vm_ops->migrate)
                return 0;
 
-       if (!sysfs_get_active_two(attr_sd))
+       if (!sysfs_get_active(attr_sd))
                return 0;
 
        ret = bb->vm_ops->migrate(vma, from, to, flags);
 
-       sysfs_put_active_two(attr_sd);
+       sysfs_put_active(attr_sd);
        return ret;
 }
 #endif
 
-static struct vm_operations_struct bin_vm_ops = {
+static const struct vm_operations_struct bin_vm_ops = {
        .open           = bin_vma_open,
        .close          = bin_vma_close,
        .fault          = bin_fault,
@@ -362,7 +356,7 @@ static int mmap(struct file *file, struct vm_area_struct *vma)
 
        /* need attr_sd for attr, its parent for kobj */
        rc = -ENODEV;
-       if (!sysfs_get_active_two(attr_sd))
+       if (!sysfs_get_active(attr_sd))
                goto out_unlock;
 
        rc = -EINVAL;
@@ -390,7 +384,7 @@ static int mmap(struct file *file, struct vm_area_struct *vma)
        bb->vm_ops = vma->vm_ops;
        vma->vm_ops = &bin_vm_ops;
 out_put:
-       sysfs_put_active_two(attr_sd);
+       sysfs_put_active(attr_sd);
 out_unlock:
        mutex_unlock(&bb->mutex);
 
@@ -405,7 +399,7 @@ static int open(struct inode * inode, struct file * file)
        int error;
 
        /* binary file operations requires both @sd and its parent */
-       if (!sysfs_get_active_two(attr_sd))
+       if (!sysfs_get_active(attr_sd))
                return -ENODEV;
 
        error = -EACCES;
@@ -432,11 +426,11 @@ static int open(struct inode * inode, struct file * file)
        mutex_unlock(&sysfs_bin_lock);
 
        /* open succeeded, put active references */
-       sysfs_put_active_two(attr_sd);
+       sysfs_put_active(attr_sd);
        return 0;
 
  err_out:
-       sysfs_put_active_two(attr_sd);
+       sysfs_put_active(attr_sd);
        kfree(bb);
        return error;
 }
@@ -489,7 +483,8 @@ void unmap_bin_file(struct sysfs_dirent *attr_sd)
  *     @attr:  attribute descriptor.
  */
 
-int sysfs_create_bin_file(struct kobject * kobj, struct bin_attribute * attr)
+int sysfs_create_bin_file(struct kobject *kobj,
+                         const struct bin_attribute *attr)
 {
        BUG_ON(!kobj || !kobj->sd || !attr);
 
@@ -503,7 +498,8 @@ int sysfs_create_bin_file(struct kobject * kobj, struct bin_attribute * attr)
  *     @attr:  attribute descriptor.
  */
 
-void sysfs_remove_bin_file(struct kobject * kobj, struct bin_attribute * attr)
+void sysfs_remove_bin_file(struct kobject *kobj,
+                          const struct bin_attribute *attr)
 {
        sysfs_hash_and_remove(kobj->sd, attr->attr.name);
 }