Blob Blame History Raw
From: Fan Guo <guofan5@huawei.com>
Date: Fri, 12 Jun 2020 14:38:24 +0800
Subject: RDMA/mad: Fix possible memory leak in ib_mad_post_receive_mads()
Patch-mainline: v5.8-rc3
Git-commit: a17f4bed811c60712d8131883cdba11a105d0161
References: git-fixes

If ib_dma_mapping_error() returns non-zero value,
ib_mad_post_receive_mads() will jump out of loops and return -ENOMEM
without freeing mad_priv. Fix this memory-leak problem by freeing mad_priv
in this case.

Fixes: 2c34e68f4261 ("IB/mad: Check and handle potential DMA mapping errors")
Link: https://lore.kernel.org/r/20200612063824.180611-1-guofan5@huawei.com
Signed-off-by: Fan Guo <guofan5@huawei.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Acked-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
---
 drivers/infiniband/core/mad.c |    1 +
 1 file changed, 1 insertion(+)

--- a/drivers/infiniband/core/mad.c
+++ b/drivers/infiniband/core/mad.c
@@ -2941,6 +2941,7 @@ static int ib_mad_post_receive_mads(stru
 						 DMA_FROM_DEVICE);
 		if (unlikely(ib_dma_mapping_error(qp_info->port_priv->device,
 						  sg_list.addr))) {
+			kfree(mad_priv);
 			ret = -ENOMEM;
 			break;
 		}