Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2163066rdd; Fri, 12 Jan 2024 00:56:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IEdplmpRBHMDtvDNC+wGf0BJXy4N82fkYZqTudHSGGg9vzMZVLf3Rrvj093fUGuE/BHIl4g X-Received: by 2002:a05:622a:111:b0:429:ab03:833e with SMTP id u17-20020a05622a011100b00429ab03833emr1426802qtw.7.1705049762023; Fri, 12 Jan 2024 00:56:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705049762; cv=none; d=google.com; s=arc-20160816; b=k0KxCVMFofr1CWYzsEz2rgexzgbEL9vAJ+oyioVq64wxNNKm8boQl9YbiIJrYZc/fR sAXBLri+DGOPfHApiM2v90shxx+dzS4puBCACDj7NX4d0uige92vFpfkTU2CXvkZUDDn bNNO4zr/YCIgn8uzhVOaSb6JNtL6ZXlGMD3fMlrwpOiWoPbmV6FaTCYBEn0gjcqPFqIP lZC++iWcTdyvx94AVVTvB1uZyAuu18XrjtUPjfTrSkpWaZpdssldmVaYlkzCPJThrhx2 xPbPf9BvmZ/e4JpW79fhuLkIvAwfGO2lj/JlR6QjkjdKFVe+Q/eKPC6N4nekIN2Gr7nT +E6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=NrMDSXDk8O5xXy284aTALVTaGoiFV0ib0r/VU53ll3M=; fh=P/+JlLApqQW3tnJcR2fn5WOVncnwhwkoNZV49Gf/xuQ=; b=U4Txn0tAn40xKKquCoNaKfn25gLogZaZxG4FdV9/A3YBr+NrwW5cJ+03+tHCs+NRTt WK/rZG/btIUTTpvR3x4+w+Om1EHWSGeFsPNz5Ty9LPkiXbcj/QDRd70liRRLDhK6obnH oD/sk3q7I4x4vltyUIZS17pqFObvCgMs9l82C1rVecdvVO0jIdPfLR75wPYTX41MKQ4R n3V3TOmoqndyV0TC4hyYhBw7fG4nedZoX2nzcSCvhPFVeiqTibj8mA+hXldW+U9CvQSE HpgajfjjcDCpnz7MrDPYO+EcOnRe52LMwwDW864EYKQ4O7BmLFJbiI89D4zMHvg37ifx HDGA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-24438-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24438-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id o19-20020ac85a53000000b00429917b97c9si2674008qta.382.2024.01.12.00.56.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 00:56:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24438-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-24438-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24438-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C41001C24FF0 for ; Fri, 12 Jan 2024 08:56:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 519E45577C; Fri, 12 Jan 2024 08:55:50 +0000 (UTC) Received: from sgoci-sdnproxy-4.icoremail.net (sgoci-sdnproxy-4.icoremail.net [129.150.39.64]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 878D562A; Fri, 12 Jan 2024 08:55:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zju.edu.cn Received: from luzhipeng.223.5.5.5 (unknown [39.174.92.167]) by mail-app4 (Coremail) with SMTP id cS_KCgD3Wd2F_qBlVwi5AA--.22436S2; Fri, 12 Jan 2024 16:55:35 +0800 (CST) From: Zhipeng Lu To: alexious@zju.edu.cn Cc: Dennis Dalessandro , Jason Gunthorpe , Leon Romanovsky , Jubin John , Mitko Haralanov , Ravi Krishnaswamy , Harish Chegondi , Brendan Cunningham , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] IB/hfi1: fix a memleak in init_credit_return Date: Fri, 12 Jan 2024 16:55:23 +0800 Message-Id: <20240112085523.3731720-1-alexious@zju.edu.cn> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cS_KCgD3Wd2F_qBlVwi5AA--.22436S2 X-Coremail-Antispam: 1UD129KBjvdXoWrKFWkCrWxZrWxAF4kuFyDWrg_yoWkWFgEvF 18Zr97Xw1DCrn3A34DGr43ZF9Fgw12qr18Wrn7Kw1akFy7urn8A393Zrs8u39rZF4xKFWD WF43urWxZF13ujkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbVxFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr1j 6rxdM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s 0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xII jxv20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr 1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxa n2IY04v7MxkIecxEwVAFwVW8ZwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJV W8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF 1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6x IIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY 6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa 73UjIFyTuYvjfU538nUUUUU X-CM-SenderInfo: qrsrjiarszq6lmxovvfxof0/ When dma_alloc_coherent fails to allocate dd->cr_base[i].va, init_credit_return should deallocate dd->cr_base and dd->cr_base[i] that allocated before. Or those resources would be never freed and a memleak is triggered. Fixes: 7724105686e7 ("IB/hfi1: add driver files") Signed-off-by: Zhipeng Lu --- drivers/infiniband/hw/hfi1/pio.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/hfi1/pio.c b/drivers/infiniband/hw/hfi1/pio.c index 68c621ff59d0..5a91cbda4aee 100644 --- a/drivers/infiniband/hw/hfi1/pio.c +++ b/drivers/infiniband/hw/hfi1/pio.c @@ -2086,7 +2086,7 @@ int init_credit_return(struct hfi1_devdata *dd) "Unable to allocate credit return DMA range for NUMA %d\n", i); ret = -ENOMEM; - goto done; + goto free_cr_base; } } set_dev_node(&dd->pcidev->dev, dd->node); @@ -2094,6 +2094,10 @@ int init_credit_return(struct hfi1_devdata *dd) ret = 0; done: return ret; + +free_cr_base: + free_credit_return(dd); + goto done; } void free_credit_return(struct hfi1_devdata *dd) -- 2.34.1