Skip to content

Commit 5da4e68

Browse files
author
Al Viro
committed
devtmpfs: get rid of bogus mkdir in create_path()
We do _NOT_ want to mkdir the path itself - we are preparing to mknod it, after all. Normally it'll fail with -ENOENT and just do nothing, but if somebody has created the parent in the meanwhile, we'll get buggered... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 69753a0 commit 5da4e68

1 file changed

Lines changed: 18 additions & 24 deletions

File tree

‎drivers/base/devtmpfs.c‎

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -164,34 +164,28 @@ static int dev_mkdir(const char *name, mode_t mode)
164164

165165
static int create_path(const char *nodepath)
166166
{
167+
char *path;
168+
char *s;
167169
int err;
168170

169-
err = dev_mkdir(nodepath, 0755);
170-
if (err == -ENOENT) {
171-
char *path;
172-
char *s;
171+
/* parent directories do not exist, create them */
172+
path = kstrdup(nodepath, GFP_KERNEL);
173+
if (!path)
174+
return -ENOMEM;
173175

174-
/* parent directories do not exist, create them */
175-
path = kstrdup(nodepath, GFP_KERNEL);
176-
if (!path) {
177-
err = -ENOMEM;
178-
goto out;
179-
}
180-
s = path;
181-
for (;;) {
182-
s = strchr(s, '/');
183-
if (!s)
184-
break;
185-
s[0] = '\0';
186-
err = dev_mkdir(path, 0755);
187-
if (err && err != -EEXIST)
188-
break;
189-
s[0] = '/';
190-
s++;
191-
}
192-
kfree(path);
176+
s = path;
177+
for (;;) {
178+
s = strchr(s, '/');
179+
if (!s)
180+
break;
181+
s[0] = '\0';
182+
err = dev_mkdir(path, 0755);
183+
if (err && err != -EEXIST)
184+
break;
185+
s[0] = '/';
186+
s++;
193187
}
194-
out:
188+
kfree(path);
195189
return err;
196190
}
197191

0 commit comments

Comments
 (0)