From patchwork Sun Dec 4 15:00:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuang Wang X-Patchwork-Id: 29419 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1829890wrr; Sun, 4 Dec 2022 07:14:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf65b/YHi7H1Q+T1YQfUdgt0NrHP4gybNE5ScRn7eI8hNOsUmbYuoitBwrHxBa2A/5UZxKIN X-Received: by 2002:a17:907:a489:b0:7c0:c14f:73d7 with SMTP id vp9-20020a170907a48900b007c0c14f73d7mr9156124ejc.52.1670166886802; Sun, 04 Dec 2022 07:14:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670166886; cv=none; d=google.com; s=arc-20160816; b=vTnXsgAUS/EvmMcvtdsdKb7P3ZVaDLl6UTmYJHpP681ltd3DWqz62+z3TpRzBSNWMx vJRdWT93dFaKKZCC3rYHgsmBS4MIkMjl3Rwrq1qg2ShztOyGAw8Aq7HuX1poBE1X8NBY hFPSNzthntO0hjMPA3/zSRMIaQvm9vRGWqgQIxNZ00abwgsY0Q1RsQFaTL8hLHKQ8HWr 2evacTqhZvolyJs5DNlDfoXkfnRtjfg4wwUgCfRUedd4z03opZdSoRSChoTWZ1hg9xfr huZDt4uXFNvaF/Kr1Fpc7nfSZQz9y5boDUvh2i+n62dzFJ0wG1H/lngYfFMm+XYwJrUg MtRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from:dkim-signature; bh=IGbY0S1sNC2gjzY8/cxpSd6ihQDdO8NWLhql9cHREQI=; b=Ki8rO20ItwhvciLZG1EREpdLEFuBXyM0WpGO6HXWNnm46rAGZKNv35zqFfReIrgxPE 7HKNbO5AVoTfeIxhbQqJ1NL1kkPfOBcduE1iA0MB+bk4bGmstPM8cM4aKSxZnIP3IDt1 lslnlpBMWWfDWjICex9YpyDm470gSnZztOE199F434mTkwFXV00ooZmTfE+xLfwTvYyf pu8RY9CcvGMJQWuZ3iASGUaDFUPmzhfgOuK2VuYJ1RPh/ltVlUocNtPK1WR90uD8BM3h 9jaaZYBfem2B82/mnCyu143myNhVxPlKJfme3ST6StHFwU1K1QreSBH6VDhda2pMT8oJ FXGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=R5qfUmJN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gb5-20020a170907960500b007c0cddef31esi3749932ejc.4.2022.12.04.07.14.20; Sun, 04 Dec 2022 07:14:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=R5qfUmJN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230108AbiLDPA0 (ORCPT + 99 others); Sun, 4 Dec 2022 10:00:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229892AbiLDPAY (ORCPT ); Sun, 4 Dec 2022 10:00:24 -0500 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 560721006E; Sun, 4 Dec 2022 07:00:23 -0800 (PST) Received: by mail-pg1-x52c.google.com with SMTP id h33so8346734pgm.9; Sun, 04 Dec 2022 07:00:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=IGbY0S1sNC2gjzY8/cxpSd6ihQDdO8NWLhql9cHREQI=; b=R5qfUmJNGXBvTBKrXjhbTL9EUgWsjHPMbRQU0ZF9nal12sfWEKHl5lGcF3HmRm8Fr5 xUWJFWqJdf0pSbK4mH7StCUPKDcB8uiavmzTeVMCC1oTiaFWXEfwv4hnZuTRhf9IYpC4 VUi4Rx9MeARNjPfyCMPT9mFum+G2UgPo3haGQXL4+N71TuqXnOXSJeLtk0MoKl6w3exe kBaPbxWq0vCB8ST9aW/LnJayeMhTcyL13xrekBkYP1tfOny9rQfU7BJQGadcaVHDGNRI AmvK/HHtT8RfjlGqdcXnz4+pnCEd1HrrVwQpoGGvr3JEmO+rWyxAkoR6BkjKbA7MH9CW TFmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IGbY0S1sNC2gjzY8/cxpSd6ihQDdO8NWLhql9cHREQI=; b=65u8eHXEPcNMcNBNkt1XZdFTrzsPWgdBNS+wegr12PJCPAOZ9CqWiu18yvNAF98fEQ bNs1KIYQfY/47l7RR2GCdK7gj4f0PG0wr24Az6N5Qk7aYC49Kx7mx3zrnvgDV+nwaQAI n2EZ99sd7PCg4fA7wZ2xb5TNRCvY3pOiE9OTYwa+V/6PIVnaf91xa4p0QdPfisLMKLM9 OHJyVdSZsoco5vEeDQPsN3+c/ZHmbjVPp797F6BLptHC+AsY36uNyz7061qqtnWZNlh1 nFory/8XlIg+NoERUxGAYVmo9QLQiP2U/emF+LnzKZQ35oEP0BaE5GFSq9WiNhIyojLs W/dw== X-Gm-Message-State: ANoB5pkSbvzByIAVvv6+qn+2M39vgHpeUh5cGy/TWfotJJxMvKON3BtK sp3MxiHReD5GQNiIRHDNTtA= X-Received: by 2002:aa7:9ecb:0:b0:576:fa16:80e0 with SMTP id r11-20020aa79ecb000000b00576fa1680e0mr489416pfq.64.1670166022774; Sun, 04 Dec 2022 07:00:22 -0800 (PST) Received: from localhost.localdomain ([47.242.114.172]) by smtp.gmail.com with ESMTPSA id q9-20020a170902bd8900b0017a032d7ae4sm8849399pls.104.2022.12.04.07.00.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Dec 2022 07:00:22 -0800 (PST) From: Chuang Wang Cc: Chuang Wang , Alexander Viro , 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 Message-Id: <20221204150006.753148-1-nashuiliang@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751296913580206340?= X-GMAIL-MSGID: =?utf-8?q?1751296913580206340?= 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 --- 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; }