Skip to contentSkip to conversation

IB/mad: fix possible memory leak in ib_mad_post_receive_mads()

PATCH Applied Guo Fan 2 participants 2 messages Jun 12, 2020 – Jun 19, 2020 InfiniBand

lore
Share & tools
lore

Guo Fan

author
#0 lore raw

PATCH 1/1 IB/mad: fix possible memory leak in ib_mad_post_receive_mads()

From: Fan Guo <[email protected]>

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. We fix this memory-leak problem by freeing mad_priv in this case.

Fixes 2c34e68f4261 ("IB/mad: Check and handle potential DMA mapping errors")
---
 drivers/infiniband/core/mad.c | 1 +
 1 file changed, 1 insertion(+)
drivers/infiniband/core/mad.c +1 -0
index 186e0d652e8b..5e080191a725 100644
@@ -2718,6 +2718,7 @@ static int ib_mad_post_receive_mads(struct ib_mad_qp_info *qp_info,
 						 DMA_FROM_DEVICE);
 		if (unlikely(ib_dma_mapping_error(qp_info->port_priv->device,
 						  sg_list.addr))) {
+			kfree(mad_priv);
 			ret = -ENOMEM;
 			break;
 		}
Signature · 1 line
2.25.1
maintainer Applied
#1 lore raw
Quoted 11 lines · Guo Fan

From: Fan Guo <[email protected]>

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. We fix this memory-leak problem by freeing mad_priv in this case.

Fixes 2c34e68f4261 ("IB/mad: Check and handle potential DMA mapping errors")
---
 drivers/infiniband/core/mad.c | 1 +
 1 file changed, 1 insertion(+)

Applied to for-rc, thanks

Jason