From: Chuang Wang <nashuiliang@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Chuang Wang <nashuiliang@gmail.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] mount: rebuild error handling in do_new_mount
Date: Sun, 4 Dec 2022 23:00:05 +0800 [thread overview]
Message-ID: <20221204150006.753148-1-nashuiliang@gmail.com> (raw)
When a function execution error is detected in do_new_mount, it should
return immediately. Using this can make the code easier to understand.
Signed-off-by: Chuang Wang <nashuiliang@gmail.com>
---
fs/namespace.c | 53 ++++++++++++++++++++++++++++++++------------------
1 file changed, 34 insertions(+), 19 deletions(-)
diff --git a/fs/namespace.c b/fs/namespace.c
index ab467ee58341..a544e814b326 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -3116,36 +3116,51 @@ static int do_new_mount(struct path *path, const char *fstype, int sb_flags,
if (!type)
return -ENODEV;
+ fc = fs_context_for_mount(type, sb_flags);
+ put_filesystem(type);
+ if (IS_ERR(fc))
+ return PTR_ERR(fc);
+
+ /* subtype */
if (type->fs_flags & FS_HAS_SUBTYPE) {
subtype = strchr(fstype, '.');
if (subtype) {
subtype++;
if (!*subtype) {
- put_filesystem(type);
- return -EINVAL;
+ err = -EINVAL;
+ goto err_fc;
}
+
+ err = vfs_parse_fs_string(fc, "subtype",
+ subtype, strlen(subtype));
+ if (err)
+ goto err_fc;
}
}
- fc = fs_context_for_mount(type, sb_flags);
- put_filesystem(type);
- if (IS_ERR(fc))
- return PTR_ERR(fc);
-
- if (subtype)
- err = vfs_parse_fs_string(fc, "subtype",
- subtype, strlen(subtype));
- if (!err && name)
+ /* source */
+ if (name) {
err = vfs_parse_fs_string(fc, "source", name, strlen(name));
- if (!err)
- err = parse_monolithic_mount_data(fc, data);
- if (!err && !mount_capable(fc))
- err = -EPERM;
- if (!err)
- err = vfs_get_tree(fc);
- if (!err)
- err = do_new_mount_fc(fc, path, mnt_flags);
+ if (err)
+ goto err_fc;
+ }
+
+ /* monolithic data */
+ err = parse_monolithic_mount_data(fc, data);
+ if (err)
+ goto err_fc;
+
+ err = -EPERM;
+ if (!mount_capable(fc))
+ goto err_fc;
+
+ err = vfs_get_tree(fc);
+ if (err)
+ goto err_fc;
+
+ err = do_new_mount_fc(fc, path, mnt_flags);
+err_fc:
put_fs_context(fc);
return err;
}
--
2.37.2
next reply other threads:[~2022-12-04 15:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-04 15:00 Chuang Wang [this message]
2022-12-10 23:39 ` Al Viro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221204150006.753148-1-nashuiliang@gmail.com \
--to=nashuiliang@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®