From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDA9013B295; Tue, 27 Feb 2024 13:56:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709042196; cv=none; b=F0cqnDgMd90QAYNIuQqfxhYHC1RHyAHzHs88mwag9QNUyryB84T0wOjDus+L1nP08/mTZc4D69NEBso96xBewNQ2ctNamUsydBAx39oGHEZIDIijzKXRb2cuTM9LU0jReRIw6Z/JOr6Ov7bXLpNaYEm1v4id9QGsLl3Z6KXXRYI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709042196; c=relaxed/simple; bh=wI55N/lAmlVSXvteM3wVCkLa3vzeRUZP2sSL7J8PfHM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=te+V+ujUbx3cezSaNtGSpfueCxzE3UXutczDdLRYGP5NbtOEMvEdcKaxvK31TWEvU9EnUb/JJ623ndP968FTgZmZXfFWwXW/xNYi19gZMi8mQJN8dYUTgGTkaySdA1Ma7wQPHRKJd+l8DlqU/SImcHJYa9BjFoP2tSas0tFZySk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=FBVsUky7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="FBVsUky7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06492C433F1; Tue, 27 Feb 2024 13:56:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1709042195; bh=wI55N/lAmlVSXvteM3wVCkLa3vzeRUZP2sSL7J8PfHM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FBVsUky7Eavrx/mAyfc4vILo0E3qnf+JJ1fNtjssZyuNx6zcZRF2HmtsYifhOdugA LBzanl/RzMnloaPf+its6Tgw7i+zo3yMVooZX5oC3pxyPzZt6Eih05N7vZWOTovARd y2iO+0ByFPrFBNqQhxUCjsMxY2JtUA2qt5/8wVZM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhipeng Lu , Dennis Dalessandro , Leon Romanovsky , Sasha Levin Subject: [PATCH 6.6 211/299] IB/hfi1: Fix a memleak in init_credit_return Date: Tue, 27 Feb 2024 14:25:22 +0100 Message-ID: <20240227131632.580333139@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240227131625.847743063@linuxfoundation.org> References: <20240227131625.847743063@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zhipeng Lu [ Upstream commit 809aa64ebff51eb170ee31a95f83b2d21efa32e2 ] 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 Link: https://lore.kernel.org/r/20240112085523.3731720-1-alexious@zju.edu.cn Acked-by: Dennis Dalessandro Signed-off-by: Leon Romanovsky Signed-off-by: Sasha Levin --- 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 dfea53e0fdeb8..5eb309ead7076 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.43.0