Skip to content

Commit 61172ea

Browse files
author
Christoph Hellwig
committed
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>
1 parent 04015e3 commit 61172ea

File tree

2 files changed

+20
-26
lines changed

2 files changed

+20
-26
lines changed

fs/proc/generic.c

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -346,26 +346,29 @@ static const struct inode_operations proc_dir_inode_operations = {
346346
.setattr = proc_notify_change,
347347
};
348348

349-
static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
349+
/* returns the registered entry, or frees dp and returns NULL on failure */
350+
struct proc_dir_entry *proc_register(struct proc_dir_entry *dir,
351+
struct proc_dir_entry *dp)
350352
{
351-
int ret;
352-
353-
ret = proc_alloc_inum(&dp->low_ino);
354-
if (ret)
355-
return ret;
353+
if (proc_alloc_inum(&dp->low_ino))
354+
goto out_free_entry;
356355

357356
write_lock(&proc_subdir_lock);
358357
dp->parent = dir;
359358
if (pde_subdir_insert(dir, dp) == false) {
360359
WARN(1, "proc_dir_entry '%s/%s' already registered\n",
361360
dir->name, dp->name);
362361
write_unlock(&proc_subdir_lock);
363-
proc_free_inum(dp->low_ino);
364-
return -EEXIST;
362+
goto out_free_inum;
365363
}
366364
write_unlock(&proc_subdir_lock);
367365

368-
return 0;
366+
return dp;
367+
out_free_inum:
368+
proc_free_inum(dp->low_ino);
369+
out_free_entry:
370+
pde_free(dp);
371+
return NULL;
369372
}
370373

371374
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,
443446
if (ent->data) {
444447
strcpy((char*)ent->data,dest);
445448
ent->proc_iops = &proc_link_inode_operations;
446-
if (proc_register(parent, ent) < 0) {
447-
pde_free(ent);
448-
ent = NULL;
449-
}
449+
ent = proc_register(parent, ent);
450450
} else {
451451
pde_free(ent);
452452
ent = NULL;
@@ -470,11 +470,9 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
470470
ent->proc_fops = &proc_dir_operations;
471471
ent->proc_iops = &proc_dir_inode_operations;
472472
parent->nlink++;
473-
if (proc_register(parent, ent) < 0) {
474-
pde_free(ent);
473+
ent = proc_register(parent, ent);
474+
if (!ent)
475475
parent->nlink--;
476-
ent = NULL;
477-
}
478476
}
479477
return ent;
480478
}
@@ -505,11 +503,9 @@ struct proc_dir_entry *proc_create_mount_point(const char *name)
505503
ent->proc_fops = NULL;
506504
ent->proc_iops = NULL;
507505
parent->nlink++;
508-
if (proc_register(parent, ent) < 0) {
509-
pde_free(ent);
506+
ent = proc_register(parent, ent);
507+
if (!ent)
510508
parent->nlink--;
511-
ent = NULL;
512-
}
513509
}
514510
return ent;
515511
}
@@ -539,11 +535,7 @@ struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
539535
pde->proc_fops = proc_fops;
540536
pde->data = data;
541537
pde->proc_iops = &proc_file_inode_operations;
542-
if (proc_register(parent, pde) < 0)
543-
goto out_free;
544-
return pde;
545-
out_free:
546-
pde_free(pde);
538+
return proc_register(parent, pde);
547539
out:
548540
return NULL;
549541
}

fs/proc/internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
162162
/*
163163
* generic.c
164164
*/
165+
struct proc_dir_entry *proc_register(struct proc_dir_entry *dir,
166+
struct proc_dir_entry *dp);
165167
extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
166168
struct dentry *proc_lookup_de(struct inode *, struct dentry *, struct proc_dir_entry *);
167169
extern int proc_readdir(struct file *, struct dir_context *);

0 commit comments

Comments
 (0)