Skip to contentSkip to conversation

proc: cleanup: remove unused assignments

PATCH In review Dan Carpenter 5 participants 6 messages Mar 6, 2010 – Mar 11, 2010 Proc filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 proc: cleanup: remove unused assignments

I removed 3 unused assignments. The first two get reset on the first statement of their functions. For "err" in root.c we don't return an error and we don't use the variable again.

fs/proc/base.c +2 -2
index a731084..875d636 100644
@@ -2434,7 +2434,7 @@ static struct dentry *proc_base_instantiate(struct inode *dir,
 	const struct pid_entry *p = ptr;
 	struct inode *inode;
 	struct proc_inode *ei;
-	struct dentry *error = ERR_PTR(-EINVAL);
+	struct dentry *error;
 
 	/* Allocate the inode */
 	error = ERR_PTR(-ENOMEM);
@@ -2784,7 +2784,7 @@ out:
 
 struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd)
 {
-	struct dentry *result = ERR_PTR(-ENOENT);
+	struct dentry *result;
 	struct task_struct *task;
 	unsigned tgid;
 	struct pid_namespace *ns;
fs/proc/root.c +0 -1
index 757c069..4258384 100644
@@ -110,7 +110,6 @@ void __init proc_root_init(void)
 	if (err)
 		return;
 	proc_mnt = kern_mount_data(&proc_fs_type, &init_pid_ns);
-	err = PTR_ERR(proc_mnt);
 	if (IS_ERR(proc_mnt)) {
 		unregister_filesystem(&proc_fs_type);
 		return;
#1 lore raw
Quoted 4 lines · Dan Carpenter

I removed 3 unused assignments. The first two get reset on the first statement of their functions. For "err" in root.c we don't return an error and we don't use the variable again.

Looks like the obviously nice cleanup to me.

Quoted 36 lines
fs/proc/base.c +2 -2
index a731084..875d636 100644
@@ -2434,7 +2434,7 @@ static struct dentry *proc_base_instantiate(struct inode *dir,
 	const struct pid_entry *p = ptr;
 	struct inode *inode;
 	struct proc_inode *ei;
-	struct dentry *error = ERR_PTR(-EINVAL);
+	struct dentry *error;
 
 	/* Allocate the inode */
 	error = ERR_PTR(-ENOMEM);
@@ -2784,7 +2784,7 @@ out:
 
 struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd)
 {
-	struct dentry *result = ERR_PTR(-ENOENT);
+	struct dentry *result;
 	struct task_struct *task;
 	unsigned tgid;
 	struct pid_namespace *ns;
fs/proc/root.c +0 -1
index 757c069..4258384 100644
@@ -110,7 +110,6 @@ void __init proc_root_init(void)
 	if (err)
 		return;
 	proc_mnt = kern_mount_data(&proc_fs_type, &init_pid_ns);
-	err = PTR_ERR(proc_mnt);
 	if (IS_ERR(proc_mnt)) {
 		unregister_filesystem(&proc_fs_type);
 		return;
#2 lore raw
Quoted 7 lines · Oleg Nesterov
Quoted 4 lines · Dan Carpenter

I removed 3 unused assignments. The first two get reset on the first statement of their functions. For "err" in root.c we don't return an error and we don't use the variable again.

Looks like the obviously nice cleanup to me.

Yup. Particularly the last one might confuse someone...

Quoted 36 lines
Quoted 36 lines
fs/proc/base.c +2 -2
index a731084..875d636 100644
@@ -2434,7 +2434,7 @@ static struct dentry *proc_base_instantiate(struct inode *dir,
 	const struct pid_entry *p = ptr;
 	struct inode *inode;
 	struct proc_inode *ei;
-	struct dentry *error = ERR_PTR(-EINVAL);
+	struct dentry *error;
 
 	/* Allocate the inode */
 	error = ERR_PTR(-ENOMEM);
@@ -2784,7 +2784,7 @@ out:
 
 struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd)
 {
-	struct dentry *result = ERR_PTR(-ENOENT);
+	struct dentry *result;
 	struct task_struct *task;
 	unsigned tgid;
 	struct pid_namespace *ns;
fs/proc/root.c +0 -1
index 757c069..4258384 100644
@@ -110,7 +110,6 @@ void __init proc_root_init(void)
 	if (err)
 		return;
 	proc_mnt = kern_mount_data(&proc_fs_type, &init_pid_ns);
-	err = PTR_ERR(proc_mnt);
 	if (IS_ERR(proc_mnt)) {
 		unregister_filesystem(&proc_fs_type);
 		return;
Reviewed-by on v1 1/1
#3 lore raw
In reply to Dan Carpenter
Quoted 5 lines

I removed 3 unused assignments. The first two get reset on the first statement of their functions. For "err" in root.c we don't return an error and we don't use the variable again.

Looks good.

Quoted 35 lines
fs/proc/base.c +2 -2
index a731084..875d636 100644
@@ -2434,7 +2434,7 @@ static struct dentry *proc_base_instantiate(struct inode *dir,
 	const struct pid_entry *p = ptr;
 	struct inode *inode;
 	struct proc_inode *ei;
-	struct dentry *error = ERR_PTR(-EINVAL);
+	struct dentry *error;
 
 	/* Allocate the inode */
 	error = ERR_PTR(-ENOMEM);
@@ -2784,7 +2784,7 @@ out:
 
 struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd)
 {
-	struct dentry *result = ERR_PTR(-ENOENT);
+	struct dentry *result;
 	struct task_struct *task;
 	unsigned tgid;
 	struct pid_namespace *ns;
fs/proc/root.c +0 -1
index 757c069..4258384 100644
@@ -110,7 +110,6 @@ void __init proc_root_init(void)
 	if (err)
 		return;
 	proc_mnt = kern_mount_data(&proc_fs_type, &init_pid_ns);
-	err = PTR_ERR(proc_mnt);
 	if (IS_ERR(proc_mnt)) {
 		unregister_filesystem(&proc_fs_type);
 		return;
#4 lore raw
In reply to Dan Carpenter
Quoted 11 lines · Dan Carpenter

I removed 3 unused assignments. The first two get reset on the first
statement of their functions. For "err" in root.c we don't return an error and we don't use the variable again.

fs/proc/base.c +0 -0
index a731084..875d636 100644

fs/proc/base.c static struct dentry *proc_base_instantiate(struct inode *dir, · line 2440

Quoted 8 lines
fs/proc/base.c +1 -1
@@ -2434,7 +2434,7 @@ static struct dentry *proc_base_instantiate(struct inode *dir,
 	const struct pid_entry *p = ptr;
 	struct inode *inode;
 	struct proc_inode *ei;
-	struct dentry *error = ERR_PTR(-EINVAL);
+	struct dentry *error;
 
 	/* Allocate the inode */
 	error = ERR_PTR(-ENOMEM);

why not do it like this:

@@ -2434,7 +2434,7 @@ static struct dentry *proc_base_instantiate(struct inode *dir,

	const struct pid_entry *p = ptr;
	struct inode *inode;
	struct proc_inode *ei;

- struct dentry *error = ERR_PTR(-EINVAL);
+ struct dentry *error = ERR_PTR(-ENOMEM);

	/* Allocate the inode */

- error = ERR_PTR(-ENOMEM);

Quoted 23 lines
fs/proc/base.c +1 -1
@@ -2784,7 +2784,7 @@ out:
 
 struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd)
 {
-	struct dentry *result = ERR_PTR(-ENOENT);
+	struct dentry *result;
 	struct task_struct *task;
 	unsigned tgid;
 	struct pid_namespace *ns;
fs/proc/root.c +0 -1
index 757c069..4258384 100644
@@ -110,7 +110,6 @@ void __init proc_root_init(void)
 	if (err)
 		return;
 	proc_mnt = kern_mount_data(&proc_fs_type, &init_pid_ns);
-	err = PTR_ERR(proc_mnt);
 	if (IS_ERR(proc_mnt)) {
 		unregister_filesystem(&proc_fs_type);
 		return;
Signature · 2 lines
Zhenwen Xu - Seven Helight
Home Page: http://zhwen.org
#5 lore raw
Quoted 24 lines · Helight.Xu
Quoted 11 lines · Dan Carpenter

I removed 3 unused assignments. The first two get reset on the first statement of their functions. For "err" in root.c we don't return an error and we don't use the variable again.

fs/proc/base.c +0 -0
index a731084..875d636 100644

fs/proc/base.c static struct dentry *proc_base_instantiate(struct inode *dir, · line 2440

Quoted 8 lines
fs/proc/base.c +1 -1
@@ -2434,7 +2434,7 @@ static struct dentry *proc_base_instantiate(struct inode *dir,
 	const struct pid_entry *p = ptr;
 	struct inode *inode;
 	struct proc_inode *ei;
-	struct dentry *error = ERR_PTR(-EINVAL);
+	struct dentry *error;
  	/* Allocate the inode */
 	error = ERR_PTR(-ENOMEM);
 

why not do it like this:

fs/proc/base.c static struct dentry *proc_base_instantiate(struct inode *dir, · line 2440

Quoted 8 lines
fs/proc/base.c +1 -2
@@ -2434,7 +2434,7 @@ static struct dentry *proc_base_instantiate(struct inode *dir,
 	const struct pid_entry *p = ptr;
 	struct inode *inode;
 	struct proc_inode *ei;
-	struct dentry *error = ERR_PTR(-EINVAL);
+	struct dentry *error = ERR_PTR(-ENOMEM);
 
 	/* Allocate the inode */
-	error = ERR_PTR(-ENOMEM);

It's a personal preference. If anyone read the code in initializers, I wouldn't have had had anything to clean up in the first place. ;)

regards,
dan carpenter

Quoted 30 lines
Quoted 25 lines
fs/proc/base.c +1 -1
@@ -2784,7 +2784,7 @@ out:
  struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * 
 dentry, struct nameidata *nd)
 {
-	struct dentry *result = ERR_PTR(-ENOENT);
+	struct dentry *result;
 	struct task_struct *task;
 	unsigned tgid;
 	struct pid_namespace *ns;
fs/proc/root.c +0 -1
index 757c069..4258384 100644
@@ -110,7 +110,6 @@ void __init proc_root_init(void)
 	if (err)
 		return;
 	proc_mnt = kern_mount_data(&proc_fs_type, &init_pid_ns);
-	err = PTR_ERR(proc_mnt);
 	if (IS_ERR(proc_mnt)) {
 		unregister_filesystem(&proc_fs_type);
 		return;
Signature · 2 lines
Zhenwen Xu - Seven Helight
Home Page: http://zhwen.org