diff mbox

[Vivid,SRU] gut proc_register() a bit

Message ID 1448315708-9140-1-git-send-email-seth.forshee@canonical.com
State New
Headers show

Commit Message

Seth Forshee Nov. 23, 2015, 9:55 p.m. UTC
From: Al Viro <viro@zeniv.linux.org.uk>

There are only 3 callers and quite a bit of that thing is executed
exactly in one of those.  Just lift it there...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
(cherry picked from commit d443b9fd56e85c0e58d10b75cf5eb38e0b2c4c02)
BugLink: http://bugs.launchpad.net/bugs/1519106
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
---
 fs/proc/generic.c | 25 ++++++++-----------------
 1 file changed, 8 insertions(+), 17 deletions(-)

Comments

Stefan Bader Nov. 24, 2015, 10:46 a.m. UTC | #1
Only 4 callers to the modified function and the only one not updated already was
trying to set the fops/iops differently and then got the wrong values set by
proc_register.

-Stefan
Seth Forshee Nov. 24, 2015, 3:11 p.m. UTC | #2
On Tue, Nov 24, 2015 at 11:46:53AM +0100, Stefan Bader wrote:
> Only 4 callers to the modified function and the only one not updated already was
> trying to set the fops/iops differently and then got the wrong values set by
> proc_register.

Just to point this out for other reviewers - the caller which isn't
updated came after this patch upstream and so expects proc_register to
not touch the fops/iops. The fact that it does is breaking containers in
some circumstances.
Brad Figg Nov. 25, 2015, 5:10 p.m. UTC | #3
Applied to the master-next branch of Vivid.
diff mbox

Patch

diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index e0d13cb..aaabab4 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -338,29 +338,12 @@  static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
 	if (ret)
 		return ret;
 
-	if (S_ISDIR(dp->mode)) {
-		dp->proc_fops = &proc_dir_operations;
-		dp->proc_iops = &proc_dir_inode_operations;
-		dir->nlink++;
-	} else if (S_ISLNK(dp->mode)) {
-		dp->proc_iops = &proc_link_inode_operations;
-	} else if (S_ISREG(dp->mode)) {
-		BUG_ON(dp->proc_fops == NULL);
-		dp->proc_iops = &proc_file_inode_operations;
-	} else {
-		WARN_ON(1);
-		proc_free_inum(dp->low_ino);
-		return -EINVAL;
-	}
-
 	spin_lock(&proc_subdir_lock);
 	dp->parent = dir;
 	if (pde_subdir_insert(dir, dp) == false) {
 		WARN(1, "proc_dir_entry '%s/%s' already registered\n",
 		     dir->name, dp->name);
 		spin_unlock(&proc_subdir_lock);
-		if (S_ISDIR(dp->mode))
-			dir->nlink--;
 		proc_free_inum(dp->low_ino);
 		return -EEXIST;
 	}
@@ -423,6 +406,7 @@  struct proc_dir_entry *proc_symlink(const char *name,
 		ent->data = kmalloc((ent->size=strlen(dest))+1, GFP_KERNEL);
 		if (ent->data) {
 			strcpy((char*)ent->data,dest);
+			ent->proc_iops = &proc_link_inode_operations;
 			if (proc_register(parent, ent) < 0) {
 				kfree(ent->data);
 				kfree(ent);
@@ -448,8 +432,12 @@  struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
 	ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
 	if (ent) {
 		ent->data = data;
+		ent->proc_fops = &proc_dir_operations;
+		ent->proc_iops = &proc_dir_inode_operations;
+		parent->nlink++;
 		if (proc_register(parent, ent) < 0) {
 			kfree(ent);
+			parent->nlink--;
 			ent = NULL;
 		}
 	}
@@ -504,6 +492,8 @@  struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
 		return NULL;
 	}
 
+	BUG_ON(proc_fops == NULL);
+
 	if ((mode & S_IALLUGO) == 0)
 		mode |= S_IRUGO;
 	pde = __proc_create(&parent, name, mode, 1);
@@ -511,6 +501,7 @@  struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
 		goto out;
 	pde->proc_fops = proc_fops;
 	pde->data = data;
+	pde->proc_iops = &proc_file_inode_operations;
 	if (proc_register(parent, pde) < 0)
 		goto out_free;
 	return pde;