From patchwork Fri Feb 22 04:21:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lijun Ou X-Patchwork-Id: 10825167 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 42B951823 for ; Fri, 22 Feb 2019 03:39:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2FB2531A19 for ; Fri, 22 Feb 2019 03:39:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 235D031AF1; Fri, 22 Feb 2019 03:39:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A13D31A19 for ; Fri, 22 Feb 2019 03:39:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726298AbfBVDjC (ORCPT ); Thu, 21 Feb 2019 22:39:02 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:54072 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726314AbfBVDjC (ORCPT ); Thu, 21 Feb 2019 22:39:02 -0500 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 353838130646026D541A; Fri, 22 Feb 2019 11:38:59 +0800 (CST) Received: from linux-ioko.site (10.71.200.31) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.408.0; Fri, 22 Feb 2019 11:38:52 +0800 From: Lijun Ou To: , CC: , , Subject: [PATCH for-next 7/9] RDMA/hns: Prevent the gid overflow Date: Fri, 22 Feb 2019 12:21:06 +0800 Message-ID: <1550809268-125729-8-git-send-email-oulijun@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1550809268-125729-1-git-send-email-oulijun@huawei.com> References: <1550809268-125729-1-git-send-email-oulijun@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.71.200.31] X-CFilter-Loop: Reflected Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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);