Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1913811rwi; Thu, 20 Oct 2022 19:50:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5ew+oYxpEAAZtczI3/EPN5S0gQB2HjetOgI0YEJ0BJi1xl7InK8aoSJ+vtBUQzT1fltQAz X-Received: by 2002:a17:90a:890b:b0:20d:981a:a5b5 with SMTP id u11-20020a17090a890b00b0020d981aa5b5mr50893587pjn.186.1666320632922; Thu, 20 Oct 2022 19:50:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666320632; cv=none; d=google.com; s=arc-20160816; b=EhvN53Y9BIssmdCF0FOnOpr1nHiDfr1UjS0MVC+bzuL1/mXU/FqR/rnWNBEteNc4Bv L72yid4IMqKqtN2Pknr3cIJYaC6G8CPDXcIHyTiTU9QDLulsQ7c3aknX3ou+tWIo5k7Q l2yZuAXFXrt6h973tqtSwAh3dUlvz8Pqe4xhxpx46vi+V9OQ8ZEuXfZqUSiG3Di/Fkiw 295iQkECHEFKYkBRRm7Mz4dsu1zT00WZEa/yw7SPEC+36NKrHUQC7GqX5H95wb4KjtrX xylags2f9Yf9ED1VKadxKHWl7TVWhbCkNw34K++mi/B3ZDmJLjbhyxg7l3R399f2MWdj cXOg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Le9tPcdohqK3UOrnanVaHtQhl6eTkZN7tCulrd3hy6g=; b=McbIuNXNksX7Jt2zp05dwsw2Wf1wjp3Jo4YrD6BjZzP1h6pOl2kpKJ6MLOjL2j2Xhu l2+Xemvt0BTUiFjsP7Mjvqpl/3bqLD4loswxdtOT7UHI59uwnFVkfzRJdnbPONYUCcTz 3e/kn20y6D7WQsTEy54Hm2dVRGZKA2IKa4nlSZp6kC4v1r5C6PHxpRZMj58brTAnZHV6 VO7dcyWo6UnnDZW4LCy2dnQ29Xyz9RdUQRnki9y20qYis4cSjs4DAUrYty69fJnmC6xU beJITPlI9kJdXJ78TzFETOHf431L+Hwfv1T9b/rMHxa1+3RUy79bczCoJAx8WPhwtB+s pCfw== 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 x7-20020a628607000000b0052dccbf4079si21403175pfd.220.2022.10.20.19.50.20; Thu, 20 Oct 2022 19:50:32 -0700 (PDT) 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 S229981AbiJUCXA (ORCPT + 99 others); Thu, 20 Oct 2022 22:23:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229954AbiJUCWu (ORCPT ); Thu, 20 Oct 2022 22:22:50 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAD90229E64 for ; Thu, 20 Oct 2022 19:22:48 -0700 (PDT) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Mtp605R63zmVCd; Fri, 21 Oct 2022 10:18:00 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500021.china.huawei.com (7.185.36.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 10:22:46 +0800 Received: from huawei.com (10.175.103.91) by dggpemm500007.china.huawei.com (7.185.36.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 10:22:46 +0800 From: Yang Yingliang To: , , , , , , CC: , , , , , , , , , , , , , , , Subject: [PATCH 11/11] ubifs: Fix memory leak in ubifs_sysfs_init() Date: Fri, 21 Oct 2022 10:21:02 +0800 Message-ID: <20221021022102.2231464-12-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221021022102.2231464-1-yangyingliang@huawei.com> References: <20221021022102.2231464-1-yangyingliang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500007.china.huawei.com (7.185.36.183) 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 From: Liu Shixin When insmod ubifs.ko, a kmemleak reported as below: unreferenced object 0xffff88817fb1a780 (size 8): comm "insmod", pid 25265, jiffies 4295239702 (age 100.130s) hex dump (first 8 bytes): 75 62 69 66 73 00 ff ff ubifs... backtrace: [] slab_post_alloc_hook+0x9c/0x3c0 [] __kmalloc_track_caller+0x183/0x410 [] kstrdup+0x3a/0x80 [] kstrdup_const+0x66/0x80 [] kvasprintf_const+0x155/0x190 [] kobject_set_name_vargs+0x5b/0x150 [] kobject_set_name+0xbb/0xf0 [] do_one_initcall+0x14c/0x5a0 [] do_init_module+0x1f0/0x660 [] load_module+0x6d7e/0x7590 [] __do_sys_finit_module+0x19f/0x230 [] __x64_sys_finit_module+0x73/0xb0 [] do_syscall_64+0x35/0x80 [] entry_SYSCALL_64_after_hwframe+0x63/0xcd When kset_register() failed, we should call kset_put to cleanup it. Fixes: 2e3cbf425804 ("ubifs: Export filesystem error counters") Signed-off-by: Liu Shixin Signed-off-by: Yang Yingliang --- fs/ubifs/sysfs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/ubifs/sysfs.c b/fs/ubifs/sysfs.c index 06ad8fa1fcfb..54270ad36321 100644 --- a/fs/ubifs/sysfs.c +++ b/fs/ubifs/sysfs.c @@ -144,6 +144,8 @@ int __init ubifs_sysfs_init(void) kobject_set_name(&ubifs_kset.kobj, "ubifs"); ubifs_kset.kobj.parent = fs_kobj; ret = kset_register(&ubifs_kset); + if (ret) + kset_put(&ubifs_kset); return ret; } -- 2.25.1