From: Kamal Heib <kamalhe...@gmail.com>

[ Upstream commit 6d8285e604e0221b67bd5db736921b7ddce37d00 ]

Before create CQ, make sure that the requested number of CQEs is in the
supported range.

Fixes: cfdda9d76436 ("RDMA/cxgb4: Add driver for Chelsio T4 RNIC")
Link: https://lore.kernel.org/r/20201108132007.67537-1-kamalhe...@gmail.com
Signed-off-by: Kamal Heib <kamalhe...@gmail.com>
Signed-off-by: Jason Gunthorpe <j...@nvidia.com>
Signed-off-by: Sasha Levin <sas...@kernel.org>
---
 drivers/infiniband/hw/cxgb4/cq.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/infiniband/hw/cxgb4/cq.c b/drivers/infiniband/hw/cxgb4/cq.c
index b1bb61c65f4f6..16b74591a68db 100644
--- a/drivers/infiniband/hw/cxgb4/cq.c
+++ b/drivers/infiniband/hw/cxgb4/cq.c
@@ -1007,6 +1007,9 @@ int c4iw_create_cq(struct ib_cq *ibcq, const struct 
ib_cq_init_attr *attr,
        if (attr->flags)
                return -EINVAL;
 
+       if (entries < 1 || entries > ibdev->attrs.max_cqe)
+               return -EINVAL;
+
        if (vector >= rhp->rdev.lldi.nciq)
                return -EINVAL;
 
-- 
2.27.0



Reply via email to