proc: simplify proc_register calling conventions
Return registered entry on success, return NULL on failure and free the passed in entry. Also expose it in internal.h as we'll start using it in proc_net.c soon. Signed-off-by: Christoph Hellwig <hch@lst.de>
This commit is contained in:
parent
04015e3fa2
commit
61172eaea1
|
@ -346,13 +346,12 @@ static const struct inode_operations proc_dir_inode_operations = {
|
||||||
.setattr = proc_notify_change,
|
.setattr = proc_notify_change,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
|
/* returns the registered entry, or frees dp and returns NULL on failure */
|
||||||
|
struct proc_dir_entry *proc_register(struct proc_dir_entry *dir,
|
||||||
|
struct proc_dir_entry *dp)
|
||||||
{
|
{
|
||||||
int ret;
|
if (proc_alloc_inum(&dp->low_ino))
|
||||||
|
goto out_free_entry;
|
||||||
ret = proc_alloc_inum(&dp->low_ino);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
write_lock(&proc_subdir_lock);
|
write_lock(&proc_subdir_lock);
|
||||||
dp->parent = dir;
|
dp->parent = dir;
|
||||||
|
@ -360,12 +359,16 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
|
||||||
WARN(1, "proc_dir_entry '%s/%s' already registered\n",
|
WARN(1, "proc_dir_entry '%s/%s' already registered\n",
|
||||||
dir->name, dp->name);
|
dir->name, dp->name);
|
||||||
write_unlock(&proc_subdir_lock);
|
write_unlock(&proc_subdir_lock);
|
||||||
proc_free_inum(dp->low_ino);
|
goto out_free_inum;
|
||||||
return -EEXIST;
|
|
||||||
}
|
}
|
||||||
write_unlock(&proc_subdir_lock);
|
write_unlock(&proc_subdir_lock);
|
||||||
|
|
||||||
return 0;
|
return dp;
|
||||||
|
out_free_inum:
|
||||||
|
proc_free_inum(dp->low_ino);
|
||||||
|
out_free_entry:
|
||||||
|
pde_free(dp);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,
|
static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,
|
||||||
|
@ -443,10 +446,7 @@ struct proc_dir_entry *proc_symlink(const char *name,
|
||||||
if (ent->data) {
|
if (ent->data) {
|
||||||
strcpy((char*)ent->data,dest);
|
strcpy((char*)ent->data,dest);
|
||||||
ent->proc_iops = &proc_link_inode_operations;
|
ent->proc_iops = &proc_link_inode_operations;
|
||||||
if (proc_register(parent, ent) < 0) {
|
ent = proc_register(parent, ent);
|
||||||
pde_free(ent);
|
|
||||||
ent = NULL;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
pde_free(ent);
|
pde_free(ent);
|
||||||
ent = NULL;
|
ent = NULL;
|
||||||
|
@ -470,11 +470,9 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
|
||||||
ent->proc_fops = &proc_dir_operations;
|
ent->proc_fops = &proc_dir_operations;
|
||||||
ent->proc_iops = &proc_dir_inode_operations;
|
ent->proc_iops = &proc_dir_inode_operations;
|
||||||
parent->nlink++;
|
parent->nlink++;
|
||||||
if (proc_register(parent, ent) < 0) {
|
ent = proc_register(parent, ent);
|
||||||
pde_free(ent);
|
if (!ent)
|
||||||
parent->nlink--;
|
parent->nlink--;
|
||||||
ent = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ent;
|
return ent;
|
||||||
}
|
}
|
||||||
|
@ -505,11 +503,9 @@ struct proc_dir_entry *proc_create_mount_point(const char *name)
|
||||||
ent->proc_fops = NULL;
|
ent->proc_fops = NULL;
|
||||||
ent->proc_iops = NULL;
|
ent->proc_iops = NULL;
|
||||||
parent->nlink++;
|
parent->nlink++;
|
||||||
if (proc_register(parent, ent) < 0) {
|
ent = proc_register(parent, ent);
|
||||||
pde_free(ent);
|
if (!ent)
|
||||||
parent->nlink--;
|
parent->nlink--;
|
||||||
ent = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ent;
|
return ent;
|
||||||
}
|
}
|
||||||
|
@ -539,11 +535,7 @@ struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
|
||||||
pde->proc_fops = proc_fops;
|
pde->proc_fops = proc_fops;
|
||||||
pde->data = data;
|
pde->data = data;
|
||||||
pde->proc_iops = &proc_file_inode_operations;
|
pde->proc_iops = &proc_file_inode_operations;
|
||||||
if (proc_register(parent, pde) < 0)
|
return proc_register(parent, pde);
|
||||||
goto out_free;
|
|
||||||
return pde;
|
|
||||||
out_free:
|
|
||||||
pde_free(pde);
|
|
||||||
out:
|
out:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,6 +162,8 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
|
||||||
/*
|
/*
|
||||||
* generic.c
|
* generic.c
|
||||||
*/
|
*/
|
||||||
|
struct proc_dir_entry *proc_register(struct proc_dir_entry *dir,
|
||||||
|
struct proc_dir_entry *dp);
|
||||||
extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
|
extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
|
||||||
struct dentry *proc_lookup_de(struct inode *, struct dentry *, struct proc_dir_entry *);
|
struct dentry *proc_lookup_de(struct inode *, struct dentry *, struct proc_dir_entry *);
|
||||||
extern int proc_readdir(struct file *, struct dir_context *);
|
extern int proc_readdir(struct file *, struct dir_context *);
|
||||||
|
|
Loading…
Reference in New Issue