From patchwork Tue Aug 2 03:47:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mao YingMing X-Patchwork-Id: 114504 X-Patchwork-Delegate: ajit.khaparde@broadcom.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 262B6A00C3; Tue, 2 Aug 2022 05:47:53 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1214440141; Tue, 2 Aug 2022 05:47:53 +0200 (CEST) Received: from njjs-sys-mailin03.njjs.baidu.com (mx313.baidu.com [180.101.52.140]) by mails.dpdk.org (Postfix) with ESMTP id 2B829400D7 for ; Tue, 2 Aug 2022 05:47:52 +0200 (CEST) Received: from bjhw-sys-rpm015653cc5.bjhw.baidu.com (bjhw-sys-rpm015653cc5.bjhw.baidu.com [10.227.53.39]) by njjs-sys-mailin03.njjs.baidu.com (Postfix) with ESMTP id 347C6274006A; Tue, 2 Aug 2022 11:47:50 +0800 (CST) Received: from localhost (localhost [127.0.0.1]) by bjhw-sys-rpm015653cc5.bjhw.baidu.com (Postfix) with ESMTP id B0DC2D9932; Tue, 2 Aug 2022 11:47:49 +0800 (CST) From: Mao YingMing To: dev@dpdk.org Cc: Ajit Khaparde , Somnath Kotur , Kalesh AP , Thomas Monjalon Subject: [PATCHv2] net/bnxt: fix null pointer dereference in bnxt_hwrm_port_led_cfg() Date: Tue, 2 Aug 2022 11:47:49 +0800 Message-Id: <1659412069-21091-1-git-send-email-maoyingming@baidu.com> X-Mailer: git-send-email 1.7.1 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org For VFs, bp->leds is uninitialized, check bp->leds is not null before use bp->leds->num_leds. segfault backtrace in trex program when use VF: 11: bnxt_hwrm_port_led_cfg (bp=0x23ffb2140, led_on=true) 10: bnxt_dev_led_on_op (dev=0x22d7780 ) 9: rte_eth_led_on (port_id=0) 8: DpdkTRexPortAttr::set_led (this=0x23b6ce0, on=true) 7: DpdkTRexPortAttr::DpdkTRexPortAttr 6: CTRexExtendedDriverBnxt::create_port_attr 5: CPhyEthIF::Create 4: CGlobalTRex::device_start 3: CGlobalTRex::Create 2: main_test 1: main Fixes: d4d5a04 ("net/bnxt: fix unnecessary memory allocation") Cc: stable@dpdk.org Signed-off-by: Mao YingMing --- drivers/net/bnxt/bnxt_hwrm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c index 9c52573..51e1e2d 100644 --- a/drivers/net/bnxt/bnxt_hwrm.c +++ b/drivers/net/bnxt/bnxt_hwrm.c @@ -4535,7 +4535,7 @@ int bnxt_hwrm_port_led_cfg(struct bnxt *bp, bool led_on) uint16_t duration = 0; int rc, i; - if (!bp->leds->num_leds || BNXT_VF(bp)) + if (BNXT_VF(bp) || !bp->leds || !bp->leds->num_leds) return -EOPNOTSUPP; HWRM_PREP(&req, HWRM_PORT_LED_CFG, BNXT_USE_CHIMP_MB);