Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5723052rwb; Tue, 22 Nov 2022 04:11:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf5HeMNCELk9EugCTQ8/JlizD7mR2dAmGHF/qJTSNXbw+ZM1IKSVKnzvq76EjymLivU/Xvkw X-Received: by 2002:a05:6402:1243:b0:469:147e:3f0 with SMTP id l3-20020a056402124300b00469147e03f0mr12491644edw.404.1669119083233; Tue, 22 Nov 2022 04:11:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669119083; cv=none; d=google.com; s=arc-20160816; b=u7bgbkdjhxpzcFxB53VdTV1FVvoEzfZuIbZRfPqjrzVf7rUUnw+tYteU/QJ4u3t/88 6xeJIGLQfi35mPlEbhLks/czPn9m0UQ7gXVfZrIagLpI6eLj/FMryzdbrSE9UAlwcCxD 2YcmpEdHZiAXVFUPPFOlQhiBa6kKGm6tXgOoffX4OtlB0fHuUb5dG5jeG8j5G6TMCluW UKe4HvnS1xPS7SfjFrXlv2kooIizo2WZtbs007Nvg6IpuNi5yuzcPd9ecpwhvpkXNNP9 xtLTBs8mNXj4nURHm+1nuHGj6sjCCjdxCmWZHsiPT7rbLwrAp1Q66+b536MVlCAtsy0h lBpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=h3OxycKKqShEPhMLItNCMq6NIp1MTrLAsfFhF/pNzls=; b=SlkD/fQufORvI4E4YnsoMz7BHHv2+v0y0JH4pS7GvZ5epSiucJvvlWv9/zyF3pVJCa kzGb7dqe8CJgGQrnhHSQUBp/y90PQdHk5SEwQmVSA99RM/gAydaKCFrMB103XuhSnEWo A/QLRvwt0ozFiqx5TfpGTh7Ekaj6ERhgMDT2GFwGcDEPnpbkkttaNwQMOHiqgkC0iyNN Dilr/sQtvR8J0tWYyRfMJ463UZA3VDxs4KNWLfwedUm4cnU/uTbzQVbYMpKgLKnSiDyq KD43ffcWOoMntg0IrINBKk46FzGbOXw5PPbbQtjGLCKU6PjcxnVoKfHtDKPFSXH19ysL MJVA== ARC-Authentication-Results: i=1; mx.google.com; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c17-20020aa7c751000000b0046329e2724dsi10580808eds.86.2022.11.22.04.10.40; Tue, 22 Nov 2022 04:11:23 -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; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233567AbiKVLwP (ORCPT + 91 others); Tue, 22 Nov 2022 06:52:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233478AbiKVLwC (ORCPT ); Tue, 22 Nov 2022 06:52:02 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E34926123; Tue, 22 Nov 2022 03:52:01 -0800 (PST) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NGjJw1cbmz15Mp6; Tue, 22 Nov 2022 19:51:28 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 22 Nov 2022 19:51:57 +0800 Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 22 Nov 2022 19:51:57 +0800 From: Zhen Lei To: Chris Mason , Josef Bacik , David Sterba , , CC: Zhen Lei , Qu Wenruo Subject: [PATCH v2] btrfs: normalize the error handling branch in btrfs_init_sysfs() Date: Tue, 22 Nov 2022 19:50:02 +0800 Message-ID: <20221122115002.1831-1-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.37.3.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Although kset_unregister() can eventually remove all attribute files, explicitly rolling back with the matching function makes the code logic look clearer. Signed-off-by: Zhen Lei --- fs/btrfs/sysfs.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) v1 --> v2: 1. Add sysfs_unmerge_group() to unmerge group first. 2. Update subject and commit message, no resource leaks. diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 699b54b3acaae0b..74fef1f49c358cd 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -2321,8 +2321,11 @@ int __init btrfs_init_sysfs(void) #ifdef CONFIG_BTRFS_DEBUG ret = sysfs_create_group(&btrfs_kset->kobj, &btrfs_debug_feature_attr_group); - if (ret) - goto out2; + if (ret) { + sysfs_unmerge_group(&btrfs_kset->kobj, + &btrfs_static_feature_attr_group); + goto out_remove_group; + } #endif return 0; -- 2.25.1