Commit 9f987008 authored by Fan Guo's avatar Fan Guo Committed by Kelsey Skunberg

RDMA/mad: Fix possible memory leak in ib_mad_post_receive_mads()

BugLink: https://bugs.launchpad.net/bugs/1885932

[ Upstream commit a17f4bed ]

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: 2c34e68f ("IB/mad: Check and handle potential DMA mapping errors")
Link: https://lore.kernel.org/r/20200612063824.180611-1-guofan5@huawei.comSigned-off-by: default avatarFan Guo <guofan5@huawei.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarKamal Mostafa <kamal@canonical.com>
Signed-off-by: default avatarKelsey Skunberg <kelsey.skunberg@canonical.com>
parent f078e060
...@@ -2912,6 +2912,7 @@ static int ib_mad_post_receive_mads(struct ib_mad_qp_info *qp_info, ...@@ -2912,6 +2912,7 @@ static int ib_mad_post_receive_mads(struct ib_mad_qp_info *qp_info,
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
if (unlikely(ib_dma_mapping_error(qp_info->port_priv->device, if (unlikely(ib_dma_mapping_error(qp_info->port_priv->device,
sg_list.addr))) { sg_list.addr))) {
kfree(mad_priv);
ret = -ENOMEM; ret = -ENOMEM;
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment