From patchwork Tue Nov 22 11:50:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhen Lei X-Patchwork-Id: 24325 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2161405wrr; Tue, 22 Nov 2022 04:09:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf4roJrDR+lRaXv+NMyh24lzFxQKtv5xs/EI82uiOCQT01ekRvrBtZ49OcKrDfM7s0BCDyFj X-Received: by 2002:a05:6402:5007:b0:44e:baab:54e7 with SMTP id p7-20020a056402500700b0044ebaab54e7mr3891801eda.265.1669118990046; Tue, 22 Nov 2022 04:09:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669118990; cv=none; d=google.com; s=arc-20160816; b=L6txc/ZyzhZSa0zo5aHDobgWlWaadqrgtQ7ppcza31ALxAqM5tbVBYJi5d/FueqWF5 4mT7+nlJ6V+uPPU5RqqId5jjWiKjvcFHXNyC7QrVKdC/v/ktvZpKG1/pBKuVTpkDHbhj 3Uev/OE0c//TKhn1rWxCPDedw5bYbJeRAwin5mRID1qhrPle16PJg63ttaopsWzqJOPU ubdQIieyMVvhwshgFcaaY1srIuCKrBm+OJPuQCY1O8S62dTFwAiV4gMVp9ch7Le08eQc Zdui6wn/N/0Z5/uXBX9nCBTuEtevx5480hHJM9uBc08VSgulkc0eEmKb4RfCz8dOCJ50 WlGA== 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 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.09.26; Tue, 22 Nov 2022 04:09:50 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750198114318893899?= X-GMAIL-MSGID: =?utf-8?q?1750198114318893899?= 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 Reviewed-by: Qu Wenruo --- 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;