From patchwork Fri Jul 21 03:22:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajit Khaparde X-Patchwork-Id: 27092 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id A3BC07CA3; Fri, 21 Jul 2017 05:23:10 +0200 (CEST) Received: from rnd-relay.smtp.broadcom.com (lpdvrndsmtp01.broadcom.com [192.19.229.170]) by dpdk.org (Postfix) with ESMTP id 0955958EC for ; Fri, 21 Jul 2017 05:23:07 +0200 (CEST) Received: from mail-irv-17.broadcom.com (mail-irv-17.lvn.broadcom.net [10.75.224.233]) by rnd-relay.smtp.broadcom.com (Postfix) with ESMTP id D100B30C30B; Thu, 20 Jul 2017 20:23:06 -0700 (PDT) Received: from C02PT1RBG8WP.vpn.broadcom.net (unknown [10.10.117.23]) by mail-irv-17.broadcom.com (Postfix) with ESMTP id 1F3EF81EA6; Thu, 20 Jul 2017 20:23:06 -0700 (PDT) From: Ajit Khaparde To: dev@dpdk.org Cc: ferruh.yigit@intel.com, Stephen Hurd Date: Thu, 20 Jul 2017 22:22:27 -0500 Message-Id: <20170721032233.59657-4-ajit.khaparde@broadcom.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: <20170721032233.59657-1-ajit.khaparde@broadcom.com> References: <12e05afb-d540-be7a-6d26-2229fd74a969@intel.com> <20170721032233.59657-1-ajit.khaparde@broadcom.com> Subject: [dpdk-dev] [PATCH v2 2/8] net/bnxt: fix to avoid a segfault X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Fix use of local variable to avoid segfault. cnt was incorrectly tested and decremented in the loop that removes a VLAN from the table. Fixes: 36735a932ca7 ("support set VF QOS and MAC anti spoof") Signed-off-by: Stephen Hurd Signed-off-by: Ajit Khaparde --- v1->v2: incorporate review feedback. --- drivers/net/bnxt/rte_pmd_bnxt.c | 101 +++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 52 deletions(-) diff --git a/drivers/net/bnxt/rte_pmd_bnxt.c b/drivers/net/bnxt/rte_pmd_bnxt.c index 0a8fb1e..ec5855d 100644 --- a/drivers/net/bnxt/rte_pmd_bnxt.c +++ b/drivers/net/bnxt/rte_pmd_bnxt.c @@ -473,62 +473,59 @@ int rte_pmd_bnxt_set_vf_vlan_filter(uint8_t port, uint16_t vlan, for (i = 0; vf_mask; i++, vf_mask >>= 1) { cnt = bp->pf.vf_info[i].vlan_count; - if (vf_mask & 1) { - if (bp->pf.vf_info[i].vlan_table == NULL) { - rc = -1; - continue; + if ((vf_mask & 1) == 0) + continue; + + if (bp->pf.vf_info[i].vlan_table == NULL) { + rc = -1; + continue; + } + if (vlan_on) { + /* First, search for a duplicate... */ + for (j = 0; j < cnt; j++) { + if (rte_be_to_cpu_16( + bp->pf.vf_info[i].vlan_table[j].vid) == vlan) + break; } - if (vlan_on) { - /* First, search for a duplicate... */ - for (j = 0; j < cnt; j++) { - if (rte_be_to_cpu_16( - bp->pf.vf_info[i].vlan_table[j].vid) == - vlan) - break; - } - if (j == cnt) { - /* Now check that there's space */ - if (cnt == getpagesize() / - sizeof(struct bnxt_vlan_table_entry)) { - RTE_LOG(ERR, PMD, - "VF %d VLAN table is full\n", - i); - RTE_LOG(ERR, PMD, - "cannot add VLAN %u\n", - vlan); - rc = -1; - continue; - } - - cnt = bp->pf.vf_info[i].vlan_count++; - /* - * And finally, add to the - * end of the table - */ - ve = &bp->pf.vf_info[i].vlan_table[cnt]; - /* TODO: Hardcoded TPID */ - ve->tpid = rte_cpu_to_be_16(0x8100); - ve->vid = rte_cpu_to_be_16(vlan); - } - } else { - for (j = 0; cnt; j++) { - if (rte_be_to_cpu_16( - bp->pf.vf_info[i].vlan_table[j].vid) != - vlan) - continue; - memmove( - &bp->pf.vf_info[i].vlan_table[j], - &bp->pf.vf_info[i].vlan_table[j + 1], - getpagesize() - - ((j + 1) * - sizeof(struct bnxt_vlan_table_entry))); - j--; - cnt = bp->pf.vf_info[i].vlan_count--; + if (j == cnt) { + /* Now check that there's space */ + if (cnt == getpagesize() / + sizeof(struct bnxt_vlan_table_entry)) { + RTE_LOG(ERR, PMD, + "VF %d VLAN table is full\n", + i); + RTE_LOG(ERR, PMD, + "cannot add VLAN %u\n", vlan); + rc = -1; + continue; } + + /* cnt is one less than vlan_count */ + cnt = bp->pf.vf_info[i].vlan_count++; + /* + * And finally, add to the + * end of the table + */ + ve = &bp->pf.vf_info[i].vlan_table[cnt]; + /* TODO: Hardcoded TPID */ + ve->tpid = rte_cpu_to_be_16(0x8100); + ve->vid = rte_cpu_to_be_16(vlan); + } + } else { + for (j = 0; j < cnt; j++) { + if (rte_be_to_cpu_16( + bp->pf.vf_info[i].vlan_table[j].vid) != vlan) + continue; + memmove(&bp->pf.vf_info[i].vlan_table[j], + &bp->pf.vf_info[i].vlan_table[j + 1], + getpagesize() - ((j + 1) * + sizeof(struct bnxt_vlan_table_entry))); + j--; + cnt = --bp->pf.vf_info[i].vlan_count; } - rte_pmd_bnxt_set_vf_vlan_anti_spoof(dev->data->port_id, - i, bp->pf.vf_info[i].vlan_spoof_en); } + rte_pmd_bnxt_set_vf_vlan_anti_spoof(dev->data->port_id, i, + bp->pf.vf_info[i].vlan_spoof_en); } return rc;