Commit e72ceb8c authored by Eric W. Biederman's avatar Eric W. Biederman Committed by Greg Kroah-Hartman

sysfs: Remove sysfs_get/put_active_two

It turns out that holding an active reference on a directory is
pointless.  The purpose of the active references are to allows us to
block when removing sysfs entries that have custom methods so we don't
remove modules while running modular code and to keep those custom
methods from accessing data structures after the files have been
removed.  Further sysfs_remove_dir remove all elements in the
directory before removing the directory itself, so there is no chance
we will remove a directory with active children.
Signed-off-by: default avatarEric W. Biederman <ebiederm@xmission.com>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 3c31f07a
...@@ -54,14 +54,14 @@ fill_read(struct dentry *dentry, char *buffer, loff_t off, size_t count) ...@@ -54,14 +54,14 @@ fill_read(struct dentry *dentry, char *buffer, loff_t off, size_t count)
int rc; int rc;
/* need attr_sd for attr, its parent for kobj */ /* need attr_sd for attr, its parent for kobj */
if (!sysfs_get_active_two(attr_sd)) if (!sysfs_get_active(attr_sd))
return -ENODEV; return -ENODEV;
rc = -EIO; rc = -EIO;
if (attr->read) if (attr->read)
rc = attr->read(kobj, attr, buffer, off, count); rc = attr->read(kobj, attr, buffer, off, count);
sysfs_put_active_two(attr_sd); sysfs_put_active(attr_sd);
return rc; return rc;
} }
...@@ -125,14 +125,14 @@ flush_write(struct dentry *dentry, char *buffer, loff_t offset, size_t count) ...@@ -125,14 +125,14 @@ flush_write(struct dentry *dentry, char *buffer, loff_t offset, size_t count)
int rc; int rc;
/* need attr_sd for attr, its parent for kobj */ /* need attr_sd for attr, its parent for kobj */
if (!sysfs_get_active_two(attr_sd)) if (!sysfs_get_active(attr_sd))
return -ENODEV; return -ENODEV;
rc = -EIO; rc = -EIO;
if (attr->write) if (attr->write)
rc = attr->write(kobj, attr, buffer, offset, count); rc = attr->write(kobj, attr, buffer, offset, count);
sysfs_put_active_two(attr_sd); sysfs_put_active(attr_sd);
return rc; return rc;
} }
...@@ -184,12 +184,12 @@ static void bin_vma_open(struct vm_area_struct *vma) ...@@ -184,12 +184,12 @@ static void bin_vma_open(struct vm_area_struct *vma)
if (!bb->vm_ops || !bb->vm_ops->open) if (!bb->vm_ops || !bb->vm_ops->open)
return; return;
if (!sysfs_get_active_two(attr_sd)) if (!sysfs_get_active(attr_sd))
return; return;
bb->vm_ops->open(vma); 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) static void bin_vma_close(struct vm_area_struct *vma)
...@@ -201,12 +201,12 @@ static void bin_vma_close(struct vm_area_struct *vma) ...@@ -201,12 +201,12 @@ static void bin_vma_close(struct vm_area_struct *vma)
if (!bb->vm_ops || !bb->vm_ops->close) if (!bb->vm_ops || !bb->vm_ops->close)
return; return;
if (!sysfs_get_active_two(attr_sd)) if (!sysfs_get_active(attr_sd))
return; return;
bb->vm_ops->close(vma); 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) static int bin_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
...@@ -219,12 +219,12 @@ static int bin_fault(struct vm_area_struct *vma, struct vm_fault *vmf) ...@@ -219,12 +219,12 @@ static int bin_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
if (!bb->vm_ops || !bb->vm_ops->fault) if (!bb->vm_ops || !bb->vm_ops->fault)
return VM_FAULT_SIGBUS; return VM_FAULT_SIGBUS;
if (!sysfs_get_active_two(attr_sd)) if (!sysfs_get_active(attr_sd))
return VM_FAULT_SIGBUS; return VM_FAULT_SIGBUS;
ret = bb->vm_ops->fault(vma, vmf); ret = bb->vm_ops->fault(vma, vmf);
sysfs_put_active_two(attr_sd); sysfs_put_active(attr_sd);
return ret; return ret;
} }
...@@ -241,12 +241,12 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) ...@@ -241,12 +241,12 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
if (!bb->vm_ops->page_mkwrite) if (!bb->vm_ops->page_mkwrite)
return 0; return 0;
if (!sysfs_get_active_two(attr_sd)) if (!sysfs_get_active(attr_sd))
return VM_FAULT_SIGBUS; return VM_FAULT_SIGBUS;
ret = bb->vm_ops->page_mkwrite(vma, vmf); ret = bb->vm_ops->page_mkwrite(vma, vmf);
sysfs_put_active_two(attr_sd); sysfs_put_active(attr_sd);
return ret; return ret;
} }
...@@ -261,12 +261,12 @@ static int bin_access(struct vm_area_struct *vma, unsigned long addr, ...@@ -261,12 +261,12 @@ static int bin_access(struct vm_area_struct *vma, unsigned long addr,
if (!bb->vm_ops || !bb->vm_ops->access) if (!bb->vm_ops || !bb->vm_ops->access)
return -EINVAL; return -EINVAL;
if (!sysfs_get_active_two(attr_sd)) if (!sysfs_get_active(attr_sd))
return -EINVAL; return -EINVAL;
ret = bb->vm_ops->access(vma, addr, buf, len, write); ret = bb->vm_ops->access(vma, addr, buf, len, write);
sysfs_put_active_two(attr_sd); sysfs_put_active(attr_sd);
return ret; return ret;
} }
...@@ -281,12 +281,12 @@ static int bin_set_policy(struct vm_area_struct *vma, struct mempolicy *new) ...@@ -281,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) if (!bb->vm_ops || !bb->vm_ops->set_policy)
return 0; return 0;
if (!sysfs_get_active_two(attr_sd)) if (!sysfs_get_active(attr_sd))
return -EINVAL; return -EINVAL;
ret = bb->vm_ops->set_policy(vma, new); ret = bb->vm_ops->set_policy(vma, new);
sysfs_put_active_two(attr_sd); sysfs_put_active(attr_sd);
return ret; return ret;
} }
...@@ -301,12 +301,12 @@ static struct mempolicy *bin_get_policy(struct vm_area_struct *vma, ...@@ -301,12 +301,12 @@ static struct mempolicy *bin_get_policy(struct vm_area_struct *vma,
if (!bb->vm_ops || !bb->vm_ops->get_policy) if (!bb->vm_ops || !bb->vm_ops->get_policy)
return vma->vm_policy; return vma->vm_policy;
if (!sysfs_get_active_two(attr_sd)) if (!sysfs_get_active(attr_sd))
return vma->vm_policy; return vma->vm_policy;
pol = bb->vm_ops->get_policy(vma, addr); pol = bb->vm_ops->get_policy(vma, addr);
sysfs_put_active_two(attr_sd); sysfs_put_active(attr_sd);
return pol; return pol;
} }
...@@ -321,12 +321,12 @@ static int bin_migrate(struct vm_area_struct *vma, const nodemask_t *from, ...@@ -321,12 +321,12 @@ static int bin_migrate(struct vm_area_struct *vma, const nodemask_t *from,
if (!bb->vm_ops || !bb->vm_ops->migrate) if (!bb->vm_ops || !bb->vm_ops->migrate)
return 0; return 0;
if (!sysfs_get_active_two(attr_sd)) if (!sysfs_get_active(attr_sd))
return 0; return 0;
ret = bb->vm_ops->migrate(vma, from, to, flags); ret = bb->vm_ops->migrate(vma, from, to, flags);
sysfs_put_active_two(attr_sd); sysfs_put_active(attr_sd);
return ret; return ret;
} }
#endif #endif
...@@ -356,7 +356,7 @@ static int mmap(struct file *file, struct vm_area_struct *vma) ...@@ -356,7 +356,7 @@ static int mmap(struct file *file, struct vm_area_struct *vma)
/* need attr_sd for attr, its parent for kobj */ /* need attr_sd for attr, its parent for kobj */
rc = -ENODEV; rc = -ENODEV;
if (!sysfs_get_active_two(attr_sd)) if (!sysfs_get_active(attr_sd))
goto out_unlock; goto out_unlock;
rc = -EINVAL; rc = -EINVAL;
...@@ -384,7 +384,7 @@ static int mmap(struct file *file, struct vm_area_struct *vma) ...@@ -384,7 +384,7 @@ static int mmap(struct file *file, struct vm_area_struct *vma)
bb->vm_ops = vma->vm_ops; bb->vm_ops = vma->vm_ops;
vma->vm_ops = &bin_vm_ops; vma->vm_ops = &bin_vm_ops;
out_put: out_put:
sysfs_put_active_two(attr_sd); sysfs_put_active(attr_sd);
out_unlock: out_unlock:
mutex_unlock(&bb->mutex); mutex_unlock(&bb->mutex);
...@@ -399,7 +399,7 @@ static int open(struct inode * inode, struct file * file) ...@@ -399,7 +399,7 @@ static int open(struct inode * inode, struct file * file)
int error; int error;
/* binary file operations requires both @sd and its parent */ /* binary file operations requires both @sd and its parent */
if (!sysfs_get_active_two(attr_sd)) if (!sysfs_get_active(attr_sd))
return -ENODEV; return -ENODEV;
error = -EACCES; error = -EACCES;
...@@ -426,11 +426,11 @@ static int open(struct inode * inode, struct file * file) ...@@ -426,11 +426,11 @@ static int open(struct inode * inode, struct file * file)
mutex_unlock(&sysfs_bin_lock); mutex_unlock(&sysfs_bin_lock);
/* open succeeded, put active references */ /* open succeeded, put active references */
sysfs_put_active_two(attr_sd); sysfs_put_active(attr_sd);
return 0; return 0;
err_out: err_out:
sysfs_put_active_two(attr_sd); sysfs_put_active(attr_sd);
kfree(bb); kfree(bb);
return error; return error;
} }
......
...@@ -93,7 +93,7 @@ static void sysfs_unlink_sibling(struct sysfs_dirent *sd) ...@@ -93,7 +93,7 @@ static void sysfs_unlink_sibling(struct sysfs_dirent *sd)
* RETURNS: * RETURNS:
* Pointer to @sd on success, NULL on failure. * Pointer to @sd on success, NULL on failure.
*/ */
static struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd) struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd)
{ {
if (unlikely(!sd)) if (unlikely(!sd))
return NULL; return NULL;
...@@ -124,7 +124,7 @@ static struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd) ...@@ -124,7 +124,7 @@ static struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd)
* Put an active reference to @sd. This function is noop if @sd * Put an active reference to @sd. This function is noop if @sd
* is NULL. * is NULL.
*/ */
static void sysfs_put_active(struct sysfs_dirent *sd) void sysfs_put_active(struct sysfs_dirent *sd)
{ {
struct completion *cmpl; struct completion *cmpl;
int v; int v;
...@@ -144,45 +144,6 @@ static void sysfs_put_active(struct sysfs_dirent *sd) ...@@ -144,45 +144,6 @@ static void sysfs_put_active(struct sysfs_dirent *sd)
complete(cmpl); complete(cmpl);
} }
/**
* sysfs_get_active_two - get active references to sysfs_dirent and parent
* @sd: sysfs_dirent of interest
*
* Get active reference to @sd and its parent. Parent's active
* reference is grabbed first. This function is noop if @sd is
* NULL.
*
* RETURNS:
* Pointer to @sd on success, NULL on failure.
*/
struct sysfs_dirent *sysfs_get_active_two(struct sysfs_dirent *sd)
{
if (sd) {
if (sd->s_parent && unlikely(!sysfs_get_active(sd->s_parent)))
return NULL;
if (unlikely(!sysfs_get_active(sd))) {
sysfs_put_active(sd->s_parent);
return NULL;
}
}
return sd;
}
/**
* sysfs_put_active_two - put active references to sysfs_dirent and parent
* @sd: sysfs_dirent of interest
*
* Put active references to @sd and its parent. This function is
* noop if @sd is NULL.
*/
void sysfs_put_active_two(struct sysfs_dirent *sd)
{
if (sd) {
sysfs_put_active(sd);
sysfs_put_active(sd->s_parent);
}
}
/** /**
* sysfs_deactivate - deactivate sysfs_dirent * sysfs_deactivate - deactivate sysfs_dirent
* @sd: sysfs_dirent to deactivate * @sd: sysfs_dirent to deactivate
......
...@@ -85,13 +85,13 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer ...@@ -85,13 +85,13 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
return -ENOMEM; return -ENOMEM;
/* need attr_sd for attr and ops, its parent for kobj */ /* need attr_sd for attr and ops, its parent for kobj */
if (!sysfs_get_active_two(attr_sd)) if (!sysfs_get_active(attr_sd))
return -ENODEV; return -ENODEV;
buffer->event = atomic_read(&attr_sd->s_attr.open->event); buffer->event = atomic_read(&attr_sd->s_attr.open->event);
count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page); count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
sysfs_put_active_two(attr_sd); sysfs_put_active(attr_sd);
/* /*
* The code works fine with PAGE_SIZE return but it's likely to * The code works fine with PAGE_SIZE return but it's likely to
...@@ -203,12 +203,12 @@ flush_write_buffer(struct dentry * dentry, struct sysfs_buffer * buffer, size_t ...@@ -203,12 +203,12 @@ flush_write_buffer(struct dentry * dentry, struct sysfs_buffer * buffer, size_t
int rc; int rc;
/* need attr_sd for attr and ops, its parent for kobj */ /* need attr_sd for attr and ops, its parent for kobj */
if (!sysfs_get_active_two(attr_sd)) if (!sysfs_get_active(attr_sd))
return -ENODEV; return -ENODEV;
rc = ops->store(kobj, attr_sd->s_attr.attr, buffer->page, count); rc = ops->store(kobj, attr_sd->s_attr.attr, buffer->page, count);
sysfs_put_active_two(attr_sd); sysfs_put_active(attr_sd);
return rc; return rc;
} }
...@@ -344,7 +344,7 @@ static int sysfs_open_file(struct inode *inode, struct file *file) ...@@ -344,7 +344,7 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
memmove(last_sysfs_file, p, strlen(p) + 1); memmove(last_sysfs_file, p, strlen(p) + 1);
/* need attr_sd for attr and ops, its parent for kobj */ /* need attr_sd for attr and ops, its parent for kobj */
if (!sysfs_get_active_two(attr_sd)) if (!sysfs_get_active(attr_sd))
return -ENODEV; return -ENODEV;
/* every kobject with an attribute needs a ktype assigned */ /* every kobject with an attribute needs a ktype assigned */
...@@ -393,13 +393,13 @@ static int sysfs_open_file(struct inode *inode, struct file *file) ...@@ -393,13 +393,13 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
goto err_free; goto err_free;
/* open succeeded, put active references */ /* open succeeded, put active references */
sysfs_put_active_two(attr_sd); sysfs_put_active(attr_sd);
return 0; return 0;
err_free: err_free:
kfree(buffer); kfree(buffer);
err_out: err_out:
sysfs_put_active_two(attr_sd); sysfs_put_active(attr_sd);
return error; return error;
} }
...@@ -437,12 +437,12 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait) ...@@ -437,12 +437,12 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
struct sysfs_open_dirent *od = attr_sd->s_attr.open; struct sysfs_open_dirent *od = attr_sd->s_attr.open;
/* need parent for the kobj, grab both */ /* need parent for the kobj, grab both */
if (!sysfs_get_active_two(attr_sd)) if (!sysfs_get_active(attr_sd))
goto trigger; goto trigger;
poll_wait(filp, &od->poll, wait); poll_wait(filp, &od->poll, wait);
sysfs_put_active_two(attr_sd); sysfs_put_active(attr_sd);
if (buffer->event != atomic_read(&od->event)) if (buffer->event != atomic_read(&od->event))
goto trigger; goto trigger;
......
...@@ -124,8 +124,8 @@ extern const struct file_operations sysfs_dir_operations; ...@@ -124,8 +124,8 @@ extern const struct file_operations sysfs_dir_operations;
extern const struct inode_operations sysfs_dir_inode_operations; extern const struct inode_operations sysfs_dir_inode_operations;
struct dentry *sysfs_get_dentry(struct sysfs_dirent *sd); struct dentry *sysfs_get_dentry(struct sysfs_dirent *sd);
struct sysfs_dirent *sysfs_get_active_two(struct sysfs_dirent *sd); struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd);
void sysfs_put_active_two(struct sysfs_dirent *sd); void sysfs_put_active(struct sysfs_dirent *sd);
void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt, void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
struct sysfs_dirent *parent_sd); struct sysfs_dirent *parent_sd);
int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd); int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment