Skip to content

Commit 66917f8

Browse files
raven-aubrauner
authored andcommitted
autofs: add: new_inode check in autofs_fill_super()
Add missing NULL check of root_inode in autofs_fill_super(). While we are at it simplify the logic by taking advantage of the VFS cleanup procedures and get rid of the goto error handling, as suggested by Al Viro. Signed-off-by: Ian Kent <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Bill O'Donnell <[email protected]> Cc: Al Viro <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Bill O'Donnell <[email protected]> Reported-by: <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent fe2c34b commit 66917f8

File tree

1 file changed

+21
-35
lines changed

1 file changed

+21
-35
lines changed

fs/autofs/inode.c

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,7 @@ static int autofs_fill_super(struct super_block *s, struct fs_context *fc)
309309
struct autofs_fs_context *ctx = fc->fs_private;
310310
struct autofs_sb_info *sbi = s->s_fs_info;
311311
struct inode *root_inode;
312-
struct dentry *root;
313312
struct autofs_info *ino;
314-
int ret = -ENOMEM;
315313

316314
pr_debug("starting up, sbi = %p\n", sbi);
317315

@@ -328,56 +326,44 @@ static int autofs_fill_super(struct super_block *s, struct fs_context *fc)
328326
*/
329327
ino = autofs_new_ino(sbi);
330328
if (!ino)
331-
goto fail;
329+
return -ENOMEM;
332330

333331
root_inode = autofs_get_inode(s, S_IFDIR | 0755);
332+
if (!root_inode)
333+
return -ENOMEM;
334+
334335
root_inode->i_uid = ctx->uid;
335336
root_inode->i_gid = ctx->gid;
337+
root_inode->i_fop = &autofs_root_operations;
338+
root_inode->i_op = &autofs_dir_inode_operations;
336339

337-
root = d_make_root(root_inode);
338-
if (!root)
339-
goto fail_ino;
340-
341-
root->d_fsdata = ino;
340+
s->s_root = d_make_root(root_inode);
341+
if (unlikely(!s->s_root)) {
342+
autofs_free_ino(ino);
343+
return -ENOMEM;
344+
}
345+
s->s_root->d_fsdata = ino;
342346

343347
if (ctx->pgrp_set) {
344348
sbi->oz_pgrp = find_get_pid(ctx->pgrp);
345-
if (!sbi->oz_pgrp) {
346-
ret = invalf(fc, "Could not find process group %d",
347-
ctx->pgrp);
348-
goto fail_dput;
349-
}
350-
} else {
349+
if (!sbi->oz_pgrp)
350+
return invalf(fc, "Could not find process group %d",
351+
ctx->pgrp);
352+
} else
351353
sbi->oz_pgrp = get_task_pid(current, PIDTYPE_PGID);
352-
}
353354

354355
if (autofs_type_trigger(sbi->type))
355-
__managed_dentry_set_managed(root);
356-
357-
root_inode->i_fop = &autofs_root_operations;
358-
root_inode->i_op = &autofs_dir_inode_operations;
356+
/* s->s_root won't be contended so there's little to
357+
* be gained by not taking the d_lock when setting
358+
* d_flags, even when a lot mounts are being done.
359+
*/
360+
managed_dentry_set_managed(s->s_root);
359361

360362
pr_debug("pipe fd = %d, pgrp = %u\n",
361363
sbi->pipefd, pid_nr(sbi->oz_pgrp));
362364

363365
sbi->flags &= ~AUTOFS_SBI_CATATONIC;
364-
365-
/*
366-
* Success! Install the root dentry now to indicate completion.
367-
*/
368-
s->s_root = root;
369366
return 0;
370-
371-
/*
372-
* Failure ... clean up.
373-
*/
374-
fail_dput:
375-
dput(root);
376-
goto fail;
377-
fail_ino:
378-
autofs_free_ino(ino);
379-
fail:
380-
return ret;
381367
}
382368

383369
/*

0 commit comments

Comments
 (0)