Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp5146624rwp; Sun, 16 Jul 2023 21:08:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlHtu9/vzVs2WQ3ed2d/VjBpH9Xd4ff1SCYxzc1/pmDlZwYMIMOkDnwFon4PYj+mVNbYRyXh X-Received: by 2002:a05:6a00:2d9e:b0:677:cda3:2222 with SMTP id fb30-20020a056a002d9e00b00677cda32222mr14367545pfb.14.1689566923107; Sun, 16 Jul 2023 21:08:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689566923; cv=none; d=google.com; s=arc-20160816; b=kGlniqCWHY7BaEITiFvG/MZyixwU/NXRtg3JPUsqidgKrwabENoGfoTyWdSUaz0tQb iKafDGLj4GtwYAxEhiQs5CYg8gNcQeolVGwp3wJ7OjM4i5rpn37ZIl8yU7GaEnEmkCC7 8aQvrkpgLQS/EuyHgLC7kkK5CvNyaQ6Bn80+zaJ0oqZbNUzqcBn79h9CenbrHmIlND9T t/juUiumX29BvpITATNd16TlsFUpjBHXJGKAKLdh/slXAg9D2QWbDdSPuSEwk3Y35+hW EL1BZfoX0czdNAAAXyzLG8H5FP4CWnHEfPo8iwq8PnFg6oM2SsMgA7hrN+zWOgDIF9i3 NAtg== 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=5jotA7wEXA+kBVL+7pfO8P13QhG0hTePD48Ksr3+qXA=; fh=xh/716co6oUDAGUiovj2E23HdaM8ifFTiPdvK1CU8M4=; b=0g+HShg8VlDoMs2MSQOtdxUMk7yZWTzHw8j6OQdTCf/YtvNVuj+vfHUceqmtzYzMMd YOIe1r69po8kx0r8pyaa11vgP/ZzHxKokpKWH58J3c1SzswiJaHcTWg5vqNu4QQD61Kx yXQVRvqNMmZ9iKMcQCqGY3cZJVEbgTMuU+qNqgpNa7jMR3D1PfcJD76cfEY+IM46utoe Nci2FqTQuImrHQ9TbpUviVG7KgB9whMa3Xdd45PVz7prDTIUcGn9zCV6d2njOlprBHui hqtO7SuAm+Xt9eLI5rL8Ceh3DAWS4jMFGdzbtbT4KAvjWhDaxy2QTfnI9Hmi8f2GtSFm CDog== 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 bw5-20020a056a00408500b0067c47ceb886si10807521pfb.391.2023.07.16.21.08.31; Sun, 16 Jul 2023 21:08:43 -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 S229725AbjGQDzo (ORCPT + 99 others); Sun, 16 Jul 2023 23:55:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230015AbjGQDzd (ORCPT ); Sun, 16 Jul 2023 23:55:33 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CDB1E64 for ; Sun, 16 Jul 2023 20:55:31 -0700 (PDT) Received: from dggpeml500019.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4R47WW5qYyzrRpW; Mon, 17 Jul 2023 11:54:47 +0800 (CST) Received: from localhost.localdomain (10.90.76.33) by dggpeml500019.china.huawei.com (7.185.36.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 17 Jul 2023 11:55:29 +0800 From: Chenyuan Mi To: CC: , , , , Subject: [PATCH] cxl: Fix memory leak bug in alloc_mock_res() Date: Mon, 17 Jul 2023 04:16:09 +0000 Message-ID: <20230717041609.1162445-1-michenyuan@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.90.76.33] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500019.china.huawei.com (7.185.36.137) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 When gen_pool_alloc_algo() fails, the error handling path forgets to free 'res'. It would cause a memory leak bug. Fix it by add kfree() in error handling path. Signed-off-by: Chenyuan Mi --- tools/testing/cxl/test/cxl.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/testing/cxl/test/cxl.c b/tools/testing/cxl/test/cxl.c index 0e78d8e19895..250ffd147067 100644 --- a/tools/testing/cxl/test/cxl.c +++ b/tools/testing/cxl/test/cxl.c @@ -405,8 +405,10 @@ static struct cxl_mock_res *alloc_mock_res(resource_size_t size, int align) INIT_LIST_HEAD(&res->list); phys = gen_pool_alloc_algo(cxl_mock_pool, size, gen_pool_first_fit_align, &data); - if (!phys) + if (!phys) { + kfree(res); return NULL; + } res->range = (struct range) { .start = phys, -- 2.25.1