Commit e17a5765 authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by Linus Torvalds

proc: do translation + unlink atomically at remove_proc_entry()

remove_proc_entry() does

	lock
	lookup parent
	unlock
	lock
	unlink proc entry from lists
	unlock

which can be made bit more correct by doing parent translation + unlink
without dropping lock.
Signed-off-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 5748150e
...@@ -291,19 +291,17 @@ static const struct inode_operations proc_file_inode_operations = { ...@@ -291,19 +291,17 @@ static const struct inode_operations proc_file_inode_operations = {
* returns the struct proc_dir_entry for "/proc/tty/driver", and * returns the struct proc_dir_entry for "/proc/tty/driver", and
* returns "serial" in residual. * returns "serial" in residual.
*/ */
static int xlate_proc_name(const char *name, static int __xlate_proc_name(const char *name, struct proc_dir_entry **ret,
struct proc_dir_entry **ret, const char **residual) const char **residual)
{ {
const char *cp = name, *next; const char *cp = name, *next;
struct proc_dir_entry *de; struct proc_dir_entry *de;
int len; int len;
int rtn = 0;
de = *ret; de = *ret;
if (!de) if (!de)
de = &proc_root; de = &proc_root;
spin_lock(&proc_subdir_lock);
while (1) { while (1) {
next = strchr(cp, '/'); next = strchr(cp, '/');
if (!next) if (!next)
...@@ -314,17 +312,24 @@ static int xlate_proc_name(const char *name, ...@@ -314,17 +312,24 @@ static int xlate_proc_name(const char *name,
if (proc_match(len, cp, de)) if (proc_match(len, cp, de))
break; break;
} }
if (!de) { if (!de)
rtn = -ENOENT; return -ENOENT;
goto out;
}
cp += len + 1; cp += len + 1;
} }
*residual = cp; *residual = cp;
*ret = de; *ret = de;
out: return 0;
}
static int xlate_proc_name(const char *name, struct proc_dir_entry **ret,
const char **residual)
{
int rv;
spin_lock(&proc_subdir_lock);
rv = __xlate_proc_name(name, ret, residual);
spin_unlock(&proc_subdir_lock); spin_unlock(&proc_subdir_lock);
return rtn; return rv;
} }
static DEFINE_IDA(proc_inum_ida); static DEFINE_IDA(proc_inum_ida);
...@@ -797,11 +802,13 @@ void remove_proc_entry(const char *name, struct proc_dir_entry *parent) ...@@ -797,11 +802,13 @@ void remove_proc_entry(const char *name, struct proc_dir_entry *parent)
const char *fn = name; const char *fn = name;
int len; int len;
if (xlate_proc_name(name, &parent, &fn) != 0) spin_lock(&proc_subdir_lock);
if (__xlate_proc_name(name, &parent, &fn) != 0) {
spin_unlock(&proc_subdir_lock);
return; return;
}
len = strlen(fn); len = strlen(fn);
spin_lock(&proc_subdir_lock);
for (p = &parent->subdir; *p; p=&(*p)->next ) { for (p = &parent->subdir; *p; p=&(*p)->next ) {
if (proc_match(len, fn, *p)) { if (proc_match(len, fn, *p)) {
de = *p; de = *p;
......
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