Skip to content

Commit 5ca9d61

Browse files
committed
RDMA/uverbs: Fix umem release in UVERBS_METHOD_CQ_CREATE
JIRA: https://issues.redhat.com/browse/RHEL-109942 commit d871315 Author: Shuhao Fu <sfual@cse.ust.hk> Date: Fri Oct 10 10:55:17 2025 +0800 RDMA/uverbs: Fix umem release in UVERBS_METHOD_CQ_CREATE In `UVERBS_METHOD_CQ_CREATE`, umem should be released if anything goes wrong. Currently, if `create_cq_umem` fails, umem would not be released or referenced, causing a possible leak. In this patch, we release umem at `UVERBS_METHOD_CQ_CREATE`, the driver should not release umem if it returns an error code. Fixes: 1a40c36 ("RDMA/uverbs: Add a common way to create CQ with umem") Signed-off-by: Shuhao Fu <sfual@cse.ust.hk> Link: https://patch.msgid.link/aOh1le4YqtYwj-hH@osx.local Signed-off-by: Leon Romanovsky <leon@kernel.org> Signed-off-by: Kamal Heib <kheib@redhat.com>
1 parent 297e4c9 commit 5ca9d61

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

drivers/infiniband/core/uverbs_std_types_cq.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ static int UVERBS_HANDLER(UVERBS_METHOD_CQ_CREATE)(
206206
return ret;
207207

208208
err_free:
209+
ib_umem_release(umem);
209210
rdma_restrack_put(&cq->res);
210211
kfree(cq);
211212
err_event_file:

drivers/infiniband/hw/efa/efa_verbs.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,13 +1211,13 @@ int efa_create_cq_umem(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
12111211
if (umem->length < cq->size) {
12121212
ibdev_dbg(&dev->ibdev, "External memory too small\n");
12131213
err = -EINVAL;
1214-
goto err_free_mem;
1214+
goto err_out;
12151215
}
12161216

12171217
if (!ib_umem_is_contiguous(umem)) {
12181218
ibdev_dbg(&dev->ibdev, "Non contiguous CQ unsupported\n");
12191219
err = -EINVAL;
1220-
goto err_free_mem;
1220+
goto err_out;
12211221
}
12221222

12231223
cq->cpu_addr = NULL;
@@ -1246,7 +1246,7 @@ int efa_create_cq_umem(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
12461246

12471247
err = efa_com_create_cq(&dev->edev, &params, &result);
12481248
if (err)
1249-
goto err_free_mem;
1249+
goto err_free_mapped;
12501250

12511251
resp.db_off = result.db_off;
12521252
resp.cq_idx = result.cq_idx;
@@ -1294,12 +1294,10 @@ int efa_create_cq_umem(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
12941294
efa_cq_user_mmap_entries_remove(cq);
12951295
err_destroy_cq:
12961296
efa_destroy_cq_idx(dev, cq->cq_idx);
1297-
err_free_mem:
1298-
if (umem)
1299-
ib_umem_release(umem);
1300-
else
1301-
efa_free_mapped(dev, cq->cpu_addr, cq->dma_addr, cq->size, DMA_FROM_DEVICE);
1302-
1297+
err_free_mapped:
1298+
if (!umem)
1299+
efa_free_mapped(dev, cq->cpu_addr, cq->dma_addr, cq->size,
1300+
DMA_FROM_DEVICE);
13031301
err_out:
13041302
atomic64_inc(&dev->stats.create_cq_err);
13051303
return err;

0 commit comments

Comments
 (0)