From patchwork Mon Oct 17 02:51:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zeng Heng X-Patchwork-Id: 3191 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1240613wrs; Sun, 16 Oct 2022 19:54:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6GiLrcKLc2lueAbwYtoVZoJkVXn3hZvXopUnchDGVNCh0iBV/mRxpb9lhmZ8CrSDgl39Kf X-Received: by 2002:a17:907:2e01:b0:78d:e768:e845 with SMTP id ig1-20020a1709072e0100b0078de768e845mr7052336ejc.484.1665975285559; Sun, 16 Oct 2022 19:54:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665975285; cv=none; d=google.com; s=arc-20160816; b=tRcl23kvS8SipF/Zsg2j1tOk+qm71WlpdtPDTu1vkC8Hib5OiBiM2yRmXsQMbEwuXS 2H2wnOiSc8bwScwDWG0zSiROjzfm9Bj045xTSBXjHcEo3UpNGG82Da0HKMwWuXqebqJb w1nnBlBiG/+YNQ8ZK2NaDCB5XvxvKU4gXltLGwTklYmVzlogD6eLDDXkEYlj/4wTGyUJ QSQHt/T8sosf1fXlrNTVf0DbA6NJRpZ1q4D19Ke0CCY0qmm32QEgks4/4z1ap+v01Lhe m+oVE6t7a4pPles54377OQXMf2GKENT+YM0hig+dU2m55t1EWw/vWYWbWHkW1TKvbMzM dZPA== 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=+6Zty/zlD2gnwXJKOzKA86Gf+qxED13Bv3W1hP0kHqE=; b=tmbLEvQFfUb5E7LT6ZGCCvq9wNHLM759TYJqnvcF5weDCMmWXvLUgNNaRs381fLwmv XHQG0QNglkVBzg5bhQNglXnYa9JhiBVoPDtMV/8WgPcrFUcxFcH6+RL/lBmMqYOUWAbR 8tXHR905urYn+/1O4IOpUM17Y7OQ7DKNdGVf6jnX9lZ2PYOIoHerUDUKacPY+j3QCMe1 Ug9XxjIMNlQ7DNRzT19D700cuNm+jLXtc6aAilHE0JsOu0jhFWUNna71rvupQNV/KNHf jHV0NxAcAjptbCEEPBmqhIkEu5Z40hM3OFvQT9X7UKodTMvykm6+AqvznS2PZYymqDXn UcKQ== 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 m17-20020a056402511100b0045938ab7129si9031737edd.330.2022.10.16.19.54.21; Sun, 16 Oct 2022 19:54:45 -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 S231482AbiJQCx1 (ORCPT + 99 others); Sun, 16 Oct 2022 22:53:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231480AbiJQCxZ (ORCPT ); Sun, 16 Oct 2022 22:53:25 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CBC647B80; Sun, 16 Oct 2022 19:53:23 -0700 (PDT) Received: from kwepemi500024.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MrLzM5gq7zVjDc; Mon, 17 Oct 2022 10:48:47 +0800 (CST) Received: from huawei.com (10.175.103.91) by kwepemi500024.china.huawei.com (7.221.188.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 17 Oct 2022 10:53:20 +0800 From: Zeng Heng To: , , CC: , , Subject: [PATCH] xfs: fix memory leak in xfs_errortag_init Date: Mon, 17 Oct 2022 10:51:55 +0800 Message-ID: <20221017025155.1810277-1-zengheng4@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemi500024.china.huawei.com (7.221.188.100) 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?1746901701156375795?= X-GMAIL-MSGID: =?utf-8?q?1746901701156375795?= When `xfs_sysfs_init` returns failed, `mp->m_errortag` needs to free. Otherwise kmemleak would report memory leak after mounting xfs image: unreferenced object 0xffff888101364900 (size 192): comm "mount", pid 13099, jiffies 4294915218 (age 335.207s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: [<00000000f08ad25c>] __kmalloc+0x41/0x1b0 [<00000000dca9aeb6>] kmem_alloc+0xfd/0x430 [<0000000040361882>] xfs_errortag_init+0x20/0x110 [<00000000b384a0f6>] xfs_mountfs+0x6ea/0x1a30 [<000000003774395d>] xfs_fs_fill_super+0xe10/0x1a80 [<000000009cf07b6c>] get_tree_bdev+0x3e7/0x700 [<00000000046b5426>] vfs_get_tree+0x8e/0x2e0 [<00000000952ec082>] path_mount+0xf8c/0x1990 [<00000000beb1f838>] do_mount+0xee/0x110 [<000000000e9c41bb>] __x64_sys_mount+0x14b/0x1f0 [<00000000f7bb938e>] do_syscall_64+0x3b/0x90 [<000000003fcd67a9>] entry_SYSCALL_64_after_hwframe+0x63/0xcd Fixes: c68401011522 ("xfs: expose errortag knobs via sysfs") Signed-off-by: Zeng Heng Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_error.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c index 296faa41d81d..f417320ef9c0 100644 --- a/fs/xfs/xfs_error.c +++ b/fs/xfs/xfs_error.c @@ -234,13 +234,18 @@ int xfs_errortag_init( struct xfs_mount *mp) { + int ret; + mp->m_errortag = kmem_zalloc(sizeof(unsigned int) * XFS_ERRTAG_MAX, KM_MAYFAIL); if (!mp->m_errortag) return -ENOMEM; - return xfs_sysfs_init(&mp->m_errortag_kobj, &xfs_errortag_ktype, - &mp->m_kobj, "errortag"); + ret = xfs_sysfs_init(&mp->m_errortag_kobj, &xfs_errortag_ktype, + &mp->m_kobj, "errortag"); + if (ret) + kmem_free(mp->m_errortag); + return ret; } void