Commit b4c98f625fffee3a6f633082e9e4be3e952ca2ab
Committed by
Mark Fasheh
1 parent
e478bec0ba
Exists in
master
and in
7 other branches
configfs: Prevent duplicate subsystem names.
For all child objects, creation comes through mkdir(2), so duplicate names are prevented. Subsystems, though, are registered by client drivers at init_module()/__init time. This patch prevents duplicate subsystem names. Signed-off-by: Joel Becker <joel.becker@oracle.com> Signed-off-by: Mark Fasheh <mark.fasheh@oracle.com>
Showing 1 changed file with 30 additions and 2 deletions Side-by-side Diff
fs/configfs/dir.c
... | ... | @@ -86,6 +86,32 @@ |
86 | 86 | return sd; |
87 | 87 | } |
88 | 88 | |
89 | +/* | |
90 | + * | |
91 | + * Return -EEXIST if there is already a configfs element with the same | |
92 | + * name for the same parent. | |
93 | + * | |
94 | + * called with parent inode's i_mutex held | |
95 | + */ | |
96 | +int configfs_dirent_exists(struct configfs_dirent *parent_sd, | |
97 | + const unsigned char *new) | |
98 | +{ | |
99 | + struct configfs_dirent * sd; | |
100 | + | |
101 | + list_for_each_entry(sd, &parent_sd->s_children, s_sibling) { | |
102 | + if (sd->s_element) { | |
103 | + const unsigned char *existing = configfs_get_name(sd); | |
104 | + if (strcmp(existing, new)) | |
105 | + continue; | |
106 | + else | |
107 | + return -EEXIST; | |
108 | + } | |
109 | + } | |
110 | + | |
111 | + return 0; | |
112 | +} | |
113 | + | |
114 | + | |
89 | 115 | int configfs_make_dirent(struct configfs_dirent * parent_sd, |
90 | 116 | struct dentry * dentry, void * element, |
91 | 117 | umode_t mode, int type) |
... | ... | @@ -136,8 +162,10 @@ |
136 | 162 | int error; |
137 | 163 | umode_t mode = S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO; |
138 | 164 | |
139 | - error = configfs_make_dirent(p->d_fsdata, d, k, mode, | |
140 | - CONFIGFS_DIR); | |
165 | + error = configfs_dirent_exists(p->d_fsdata, d->d_name.name); | |
166 | + if (!error) | |
167 | + error = configfs_make_dirent(p->d_fsdata, d, k, mode, | |
168 | + CONFIGFS_DIR); | |
141 | 169 | if (!error) { |
142 | 170 | error = configfs_create(d, mode, init_dir); |
143 | 171 | if (!error) { |