RDMA/core: Reject zero CQE count

All drivers already ensure that the number of CQEs is at least 1.
Add this validation to the core so drivers no longer need to repeat it.
Future patches converting to the .create_user_cq() interface will remove
the per‑driver checks.

Link: https://patch.msgid.link/20260213-refactor-umem-v1-8-f3be85847922@nvidia.com
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
This commit is contained in:
Leon Romanovsky
2026-02-13 12:57:44 +02:00
parent 584ec74748
commit a291758288
4 changed files with 18 additions and 6 deletions

View File

@@ -220,6 +220,9 @@ struct ib_cq *__ib_alloc_cq(struct ib_device *dev, void *private, int nr_cqe,
struct ib_cq *cq;
int ret = -ENOMEM;
if (WARN_ON_ONCE(!nr_cqe))
return ERR_PTR(-EINVAL);
cq = rdma_zalloc_drv_obj(dev, ib_cq);
if (!cq)
return ERR_PTR(ret);

View File

@@ -1032,6 +1032,9 @@ static int create_cq(struct uverbs_attr_bundle *attrs,
if (cmd->comp_vector >= attrs->ufile->device->num_comp_vectors)
return -EINVAL;
if (!cmd->cqe)
return -EINVAL;
obj = (struct ib_ucq_object *)uobj_alloc(UVERBS_OBJECT_CQ, attrs,
&ib_dev);
if (IS_ERR(obj))

View File

@@ -84,12 +84,15 @@ static int UVERBS_HANDLER(UVERBS_METHOD_CQ_CREATE)(
ret = uverbs_copy_from(&attr.comp_vector, attrs,
UVERBS_ATTR_CREATE_CQ_COMP_VECTOR);
if (!ret)
ret = uverbs_copy_from(&attr.cqe, attrs,
UVERBS_ATTR_CREATE_CQ_CQE);
if (!ret)
ret = uverbs_copy_from(&user_handle, attrs,
UVERBS_ATTR_CREATE_CQ_USER_HANDLE);
if (ret)
return ret;
ret = uverbs_copy_from(&attr.cqe, attrs, UVERBS_ATTR_CREATE_CQ_CQE);
if (ret || !attr.cqe)
return ret ? : -EINVAL;
ret = uverbs_copy_from(&user_handle, attrs,
UVERBS_ATTR_CREATE_CQ_USER_HANDLE);
if (ret)
return ret;

View File

@@ -2203,6 +2203,9 @@ struct ib_cq *__ib_create_cq(struct ib_device *device,
if (!cq)
return ERR_PTR(-ENOMEM);
if (WARN_ON_ONCE(!cq_attr->cqe))
return ERR_PTR(-EINVAL);
cq->device = device;
cq->comp_handler = comp_handler;
cq->event_handler = event_handler;