Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp5440309rwp; Mon, 17 Jul 2023 04:22:57 -0700 (PDT) X-Google-Smtp-Source: APBJJlG7KHyfwnH+K0vx9O8KKEEpjOfpLKHOrUH7GL7RbrCMNxda+qOcpdqgArN9XB0TPRpn4Nxn X-Received: by 2002:a05:6402:38d:b0:51d:f589:9cbd with SMTP id o13-20020a056402038d00b0051df5899cbdmr10364343edv.39.1689592977340; Mon, 17 Jul 2023 04:22:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689592977; cv=none; d=google.com; s=arc-20160816; b=clsOZ5q2lKjx4cbK6Y+TR1SzqEPQlEcjXj/oeezvlWGtcwXYCX353DMFKNRTMgIzUT fybbp/6qcsiuXAPFCdBr9buyan+LQXDxLOdjKPmBmqnCyGC+leoj7g7qob+f3jq/ZQx0 tZ8xCA65KFlBQRGWwL3N2im7Z3nVcsdtQrlbTzIh7xPk/BoVppUuZzE2ArFOXooF6G9b pkRp/29cdBJrjw6TDu6l6OjOFLSV56wF21u8cwRYH1+hBDUBGEhBMvZyWnJkqEtr74E9 NNjGgR66regqtJe3UfbbmfxtYoeTReOh67PIAuQNF+PDxt5b+BAbc8EBE1OVUnW9an0L n0Iw== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=5isw2qegcNrtqcddQoIhrY5gyvhlf3f8ptvo/D9k2Ag=; fh=K2QV54rzwRiqrZOkNBtcUaj6zlBooXHSm541ODqIkbo=; b=HlbQAdI0mO5S0L6WvyPhzmzyJemQZ7OVVDe12gNPOaiZNoMVcOlebEc51LDyKzk3l8 gg6rCITHT+3eGgUgXdnym2dNIzEpKQcupyWMxEu/QO5TdCRvDC19Y6fdG5Fro2K97HEE KSf8qPrDH7//S+fT/7hKskWurBfIgR1M2nE4+Jdj1mBJ824cZKeM7KI5BoujdcSUgXEZ GUwWTNaOhoYaOtnFbYgg3oPnKAjHI92qWHsIekHWAxacR8Y/lA9JqModbXEwtSeyS+yr 7q3szPoK9t9TsHryyKUebGw5IiSm/AqP+GTeIC8nid3et51UVIiGvxj0UWBDbN+jjGPP nlwA== 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 c7-20020aa7df07000000b0051e26704e7esi13369082edy.38.2023.07.17.04.22.33; Mon, 17 Jul 2023 04:22:57 -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 S230422AbjGQKuN (ORCPT + 99 others); Mon, 17 Jul 2023 06:50:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230372AbjGQKuK (ORCPT ); Mon, 17 Jul 2023 06:50:10 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E9AAE72; Mon, 17 Jul 2023 03:50:07 -0700 (PDT) Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4R4Jgs5Yn7z6J6qr; Mon, 17 Jul 2023 18:47:37 +0800 (CST) Received: from localhost (10.202.227.76) by lhrpeml500005.china.huawei.com (7.191.163.240) 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:50:04 +0100 Date: Mon, 17 Jul 2023 11:50:03 +0100 From: Jonathan Cameron To: Chenyuan Mi CC: , , , , , Subject: Re: [PATCH] cxl: Fix memory leak bug in alloc_mock_res() Message-ID: <20230717115003.00007f73@Huawei.com> In-Reply-To: <20230717041609.1162445-1-michenyuan@huawei.com> References: <20230717041609.1162445-1-michenyuan@huawei.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.227.76] X-ClientProxiedBy: lhrpeml100005.china.huawei.com (7.191.160.25) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,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 On Mon, 17 Jul 2023 04:16:09 +0000 Chenyuan Mi wrote: > 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 +CC linux-cxl list Please make sure to include that for any future CXL patches. > --- > 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,