Skip to content

Commit 7ec2e27

Browse files
bvanasschejgunthorpe
authored andcommitted
RDMA/srp: Fix a recently introduced memory leak
Only allocate a memory registration list if it will be used and if it will be freed. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Max Gurtovoy <[email protected]> Fixes: f273ad4 ("RDMA/srp: Remove support for FMR memory registration") Signed-off-by: Bart Van Assche <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 6dc2649 commit 7ec2e27

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

drivers/infiniband/ulp/srp/ib_srp.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,6 @@ static int srp_alloc_req_data(struct srp_rdma_ch *ch)
998998
struct srp_device *srp_dev = target->srp_host->srp_dev;
999999
struct ib_device *ibdev = srp_dev->dev;
10001000
struct srp_request *req;
1001-
void *mr_list;
10021001
dma_addr_t dma_addr;
10031002
int i, ret = -ENOMEM;
10041003

@@ -1009,12 +1008,12 @@ static int srp_alloc_req_data(struct srp_rdma_ch *ch)
10091008

10101009
for (i = 0; i < target->req_ring_size; ++i) {
10111010
req = &ch->req_ring[i];
1012-
mr_list = kmalloc_array(target->mr_per_cmd, sizeof(void *),
1013-
GFP_KERNEL);
1014-
if (!mr_list)
1015-
goto out;
1016-
if (srp_dev->use_fast_reg)
1017-
req->fr_list = mr_list;
1011+
if (srp_dev->use_fast_reg) {
1012+
req->fr_list = kmalloc_array(target->mr_per_cmd,
1013+
sizeof(void *), GFP_KERNEL);
1014+
if (!req->fr_list)
1015+
goto out;
1016+
}
10181017
req->indirect_desc = kmalloc(target->indirect_size, GFP_KERNEL);
10191018
if (!req->indirect_desc)
10201019
goto out;

0 commit comments

Comments
 (0)