Skip to content

Commit 5351a56

Browse files
committed
RDMA/mlx5: Fix prefetch memory leak if get_prefetchable_mr fails
destroy_prefetch_work() must always be called if the work is not going to be queued. The num_sge also should have been set to i, not i-1 which avoids the condition where it shouldn't have been called in the first place. Cc: [email protected] Fixes: fb985e2 ("RDMA/mlx5: Use SRCU properly in ODP prefetch") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 31142a4 commit 5351a56

File tree

1 file changed

+2
-3
lines changed
  • drivers/infiniband/hw/mlx5

1 file changed

+2
-3
lines changed

drivers/infiniband/hw/mlx5/odp.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,9 +1797,7 @@ static bool init_prefetch_work(struct ib_pd *pd,
17971797
work->frags[i].mr =
17981798
get_prefetchable_mr(pd, advice, sg_list[i].lkey);
17991799
if (!work->frags[i].mr) {
1800-
work->num_sge = i - 1;
1801-
if (i)
1802-
destroy_prefetch_work(work);
1800+
work->num_sge = i;
18031801
return false;
18041802
}
18051803

@@ -1865,6 +1863,7 @@ int mlx5_ib_advise_mr_prefetch(struct ib_pd *pd,
18651863
srcu_key = srcu_read_lock(&dev->odp_srcu);
18661864
if (!init_prefetch_work(pd, advice, pf_flags, work, sg_list, num_sge)) {
18671865
srcu_read_unlock(&dev->odp_srcu, srcu_key);
1866+
destroy_prefetch_work(work);
18681867
return -EINVAL;
18691868
}
18701869
queue_work(system_unbound_wq, &work->work);

0 commit comments

Comments
 (0)