Skip to contentSkip to conversation

proc: detect duplicate names on registration

PATCH In review Alexey Dobriyan 2 participants 2 messages Nov 16, 2007 Proc filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 2/4 proc: detect duplicate names on registration

Andrew, please drop procfs-detect-duplicate-names.patch and apply this instead.
------------
[PATCH] proc: detect duplicate names on registration

From: Zhang Rui <[email protected]>

Print a warning if PDE is registered with a name which already exists in target directory.

Bug report and a simple fix can be found here:
http://bugzilla.kernel.org/show_bug.cgi?id=8798

[\n fixlet and no undescriptive variable usage --adobriyan]

---

 fs/proc/generic.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
fs/proc/generic.c +10 -0
@@ -518,6 +518,7 @@ static const struct inode_operations proc_dir_inode_operations = {
 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
 {
 	unsigned int i;
+	struct proc_dir_entry *tmp;
 	
 	i = get_inode_number();
 	if (i == 0)
@@ -536,6 +537,15 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
 	}
 
 	spin_lock(&proc_subdir_lock);
+
+	for (tmp = dir->subdir; tmp; tmp = tmp->next)
+		if (strcmp(tmp->name, dp->name) == 0) {
+			printk(KERN_WARNING "PDE '%s' already registered\n",
+				dp->name);
+			dump_stack();
+			break;
+		}
+
 	dp->next = dir->subdir;
 	dp->parent = dir;
 	dir->subdir = dp;
#1 lore raw
Quoted 27 lines · On Fri, 16 Nov 2007 18:08:40 +0300 Alexey Dobriyan wrote:

Andrew, please drop procfs-detect-duplicate-names.patch and apply this instead.
------------
[PATCH] proc: detect duplicate names on registration

From: Zhang Rui <[email protected]>

Print a warning if PDE is registered with a name which already exists in target directory.

Bug report and a simple fix can be found here:
http://bugzilla.kernel.org/show_bug.cgi?id=8798

[\n fixlet and no undescriptive variable usage --adobriyan]

---

 fs/proc/generic.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
fs/proc/generic.c +0 -0
@@ -536,6 +537,15 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
 	}
 

fs/proc/generic.c static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp · line 548

Quoted 10 lines
fs/proc/generic.c +9 -0
 	spin_lock(&proc_subdir_lock);
+
+	for (tmp = dir->subdir; tmp; tmp = tmp->next)
+		if (strcmp(tmp->name, dp->name) == 0) {
+			printk(KERN_WARNING "PDE '%s' already registered\n",
+				dp->name);
+			dump_stack();
+			break;
+		}
+

Please just s/PDE/proc_dir_entry/.

---
~Randy