Because hip08 supports up to 256 gids and hip06 supports up to 2 gids, it adds judgement for preventing the gid overflow. Signed-off-by: Lijun Ou <oulijun@xxxxxxxxxx> --- drivers/infiniband/hw/hns/hns_roce_main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/hns/hns_roce_main.c b/drivers/infiniband/hw/hns/hns_roce_main.c index 29fb4fb..e3f79d1 100644 --- a/drivers/infiniband/hw/hns/hns_roce_main.c +++ b/drivers/infiniband/hw/hns/hns_roce_main.c @@ -81,8 +81,12 @@ static int hns_roce_add_gid(const struct ib_gid_attr *attr, void **context) unsigned long flags; int ret; - if (port >= hr_dev->caps.num_ports) + if (port >= hr_dev->caps.num_ports || + attr->index > hr_dev->caps.gid_table_len[port]) { + dev_err(hr_dev->dev, "add gid failed. port - %d, index - %d\n", + port, attr->index); return -EINVAL; + } spin_lock_irqsave(&hr_dev->iboe.lock, flags); -- 1.9.1