Commit 60f126d9 authored by Eric W. Biederman's avatar Eric W. Biederman

sysctl: Comments to make the code clearer.

Document get_subdir and that find_subdir alwasy takes a reference.
Suggested-by: default avatarLucian Adrian Grijincu <lucian.grijincu@gmail.com>
Signed-off-by: default avatarEric W. Biederman <ebiederm@xmission.com>
parent 0eb97f38
...@@ -73,6 +73,7 @@ static int namecmp(const char *name1, int len1, const char *name2, int len2) ...@@ -73,6 +73,7 @@ static int namecmp(const char *name1, int len1, const char *name2, int len2)
return cmp; return cmp;
} }
/* Called under sysctl_lock */
static struct ctl_table *find_entry(struct ctl_table_header **phead, static struct ctl_table *find_entry(struct ctl_table_header **phead,
struct ctl_dir *dir, const char *name, int namelen) struct ctl_dir *dir, const char *name, int namelen)
{ {
...@@ -864,6 +865,18 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set, ...@@ -864,6 +865,18 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
return new; return new;
} }
/**
* get_subdir - find or create a subdir with the specified name.
* @dir: Directory to create the subdirectory in
* @name: The name of the subdirectory to find or create
* @namelen: The length of name
*
* Takes a directory with an elevated reference count so we know that
* if we drop the lock the directory will not go away. Upon success
* the reference is moved from @dir to the returned subdirectory.
* Upon error an error code is returned and the reference on @dir is
* simply dropped.
*/
static struct ctl_dir *get_subdir(struct ctl_dir *dir, static struct ctl_dir *get_subdir(struct ctl_dir *dir,
const char *name, int namelen) const char *name, int namelen)
{ {
...@@ -885,12 +898,14 @@ static struct ctl_dir *get_subdir(struct ctl_dir *dir, ...@@ -885,12 +898,14 @@ static struct ctl_dir *get_subdir(struct ctl_dir *dir,
if (!new) if (!new)
goto failed; goto failed;
/* Was the subdir added while we dropped the lock? */
subdir = find_subdir(dir, name, namelen); subdir = find_subdir(dir, name, namelen);
if (!IS_ERR(subdir)) if (!IS_ERR(subdir))
goto found; goto found;
if (PTR_ERR(subdir) != -ENOENT) if (PTR_ERR(subdir) != -ENOENT)
goto failed; goto failed;
/* Nope. Use the our freshly made directory entry. */
err = insert_header(dir, &new->header); err = insert_header(dir, &new->header);
subdir = ERR_PTR(err); subdir = ERR_PTR(err);
if (err) if (err)
...@@ -1190,6 +1205,7 @@ struct ctl_table_header *__register_sysctl_table( ...@@ -1190,6 +1205,7 @@ struct ctl_table_header *__register_sysctl_table(
spin_lock(&sysctl_lock); spin_lock(&sysctl_lock);
dir = &set->dir; dir = &set->dir;
/* Reference moved down the diretory tree get_subdir */
dir->header.nreg++; dir->header.nreg++;
spin_unlock(&sysctl_lock); spin_unlock(&sysctl_lock);
......
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