From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id DB76EA04DE; Fri, 23 Oct 2020 07:13:02 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BB4EB6A6A; Fri, 23 Oct 2020 07:13:01 +0200 (CEST) Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by dpdk.org (Postfix) with ESMTP id 984E86A68 for ; Fri, 23 Oct 2020 07:12:59 +0200 (CEST) Received: by mail-pf1-f194.google.com with SMTP id f19so208677pfj.11 for ; Thu, 22 Oct 2020 22:12:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version; bh=ZF9HNadC1gc3qertEdSjPZWXMXpmqWZ2rymlpMEZ1IE=; b=abYUlYjGBWFNH0AbYQBXrHuNIfxKw0nLUWEl1bfRAdhsduRAhAkknVagIipdKewEvH dj3PaTz7R+5itTOtKFeoRY5GwfI1hMPx64YA9wgvE8DlHdCiKkYhM76WmhCw3ZWPJZu+ XZFJLUrHhCJsf1Z7PySNJvSCfNKbgP72dHVA4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version; bh=ZF9HNadC1gc3qertEdSjPZWXMXpmqWZ2rymlpMEZ1IE=; b=uil2c61dl3PESjtxaYmyP9O7d7KL1nxQiYoaUdbMNCmi9+7XqIQhM5SHohHNcE42gl pN9ehd9s9Gk1azITJyRJvt5SyO/7tbb9WLqzvhzYBQv/Vbv0JMfnxe4lms/7i1nRqaKf uvBEgaXf9mQk3CUnuZef/MnMXyDPZSkqQ8bpfzYVBLR8FiUeF0s+IfB4GMyK/4a2vUzg G4nMNUzy567AnFLEMaAGaapkwfs/juEK/w07+oEi8Nh51HNvKLR2zhPxKhVe+TcsFu13 strwgkiDu35gZAO+otrQ19V+5OV8Nojq2/hcrJbBc4peemCAd9ijzB/FKEEbyRD4htqT 4sgA== X-Gm-Message-State: AOAM533bO//B5FtPL+1ftK6BMsqXZqEw8cE7gnKCAF2ec3uM/BbM1kX6 l0qKyHluMnX+MjyIrf+kl/YN7lYBRL8GMmp9otAM3xOsLdQCPGkim/05ZtAqeqp3xPYP7PyB4vz gQluQw1dTvv/ST+OWJT4Oahv6FLoWBGqViiGH4uGXJvNxpczp1TCSVPmPf2YWHbEfvA== X-Google-Smtp-Source: ABdhPJynYmZBoIDoRVTe2DevLTFVEgyyXg8XEpKCCtvsnQCVw2Gg05kxND4V0M6JBV1Xwa8I25R17w== X-Received: by 2002:a17:90a:8c8a:: with SMTP id b10mr560607pjo.127.1603429977323; Thu, 22 Oct 2020 22:12:57 -0700 (PDT) Received: from localhost.localdomain ([192.19.228.250]) by smtp.gmail.com with ESMTPSA id o2sm413190pgg.3.2020.10.22.22.12.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Oct 2020 22:12:56 -0700 (PDT) From: Ajit Khaparde To: dev@dpdk.org Cc: Kalesh AP Date: Thu, 22 Oct 2020 22:12:53 -0700 Message-Id: <20201023051253.37942-1-ajit.khaparde@broadcom.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: [dpdk-dev] [PATCH v2] net/bnxt: fix a potential resource leak 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 a potential resource leak in case of errors during dev args parsing during device probe. Fixes: 6dc83230b43b ("net/bnxt: support port representor data path") Signed-off-by: Ajit Khaparde Reviewed-by: Kalesh AP --- v1->v2: addressed the review comment. --- drivers/net/bnxt/bnxt_ethdev.c | 66 ++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 19 deletions(-) diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c index 562cf14ba4..a0e01d059d 100644 --- a/drivers/net/bnxt/bnxt_ethdev.c +++ b/drivers/net/bnxt/bnxt_ethdev.c @@ -6285,7 +6285,7 @@ static int bnxt_rep_port_probe(struct rte_pci_device *pci_dev, struct bnxt *backing_bp; uint16_t num_rep; int i, ret = 0; - struct rte_kvargs *kvlist; + struct rte_kvargs *kvlist = NULL; num_rep = eth_da.nb_representor_ports; if (num_rep > BNXT_MAX_VF_REPS) { @@ -6339,49 +6339,74 @@ static int bnxt_rep_port_probe(struct rte_pci_device *pci_dev, * Invoked as for ex: "-w 000:00:0d.0, * rep-based-pf= rep-is-pf=" */ - rte_kvargs_process(kvlist, BNXT_DEVARG_REP_IS_PF, - bnxt_parse_devarg_rep_is_pf, - (void *)&representor); + ret = rte_kvargs_process(kvlist, BNXT_DEVARG_REP_IS_PF, + bnxt_parse_devarg_rep_is_pf, + (void *)&representor); + if (ret) { + ret = -EINVAL; + goto err; + } /* * Handler for "rep_based_pf" devarg. * Invoked as for ex: "-w 000:00:0d.0, * rep-based-pf= rep-is-pf=" */ - rte_kvargs_process(kvlist, BNXT_DEVARG_REP_BASED_PF, - bnxt_parse_devarg_rep_based_pf, - (void *)&representor); + ret = rte_kvargs_process(kvlist, + BNXT_DEVARG_REP_BASED_PF, + bnxt_parse_devarg_rep_based_pf, + (void *)&representor); + if (ret) { + ret = -EINVAL; + goto err; + } /* * Handler for "rep_based_pf" devarg. * Invoked as for ex: "-w 000:00:0d.0, * rep-based-pf= rep-is-pf=" */ - rte_kvargs_process(kvlist, BNXT_DEVARG_REP_Q_R2F, - bnxt_parse_devarg_rep_q_r2f, - (void *)&representor); + ret = rte_kvargs_process(kvlist, BNXT_DEVARG_REP_Q_R2F, + bnxt_parse_devarg_rep_q_r2f, + (void *)&representor); + if (ret) { + ret = -EINVAL; + goto err; + } /* * Handler for "rep_based_pf" devarg. * Invoked as for ex: "-w 000:00:0d.0, * rep-based-pf= rep-is-pf=" */ - rte_kvargs_process(kvlist, BNXT_DEVARG_REP_Q_F2R, - bnxt_parse_devarg_rep_q_f2r, - (void *)&representor); + ret = rte_kvargs_process(kvlist, BNXT_DEVARG_REP_Q_F2R, + bnxt_parse_devarg_rep_q_f2r, + (void *)&representor); + if (ret) { + ret = -EINVAL; + goto err; + } /* * Handler for "rep_based_pf" devarg. * Invoked as for ex: "-w 000:00:0d.0, * rep-based-pf= rep-is-pf=" */ - rte_kvargs_process(kvlist, BNXT_DEVARG_REP_FC_R2F, - bnxt_parse_devarg_rep_fc_r2f, - (void *)&representor); + ret = rte_kvargs_process(kvlist, BNXT_DEVARG_REP_FC_R2F, + bnxt_parse_devarg_rep_fc_r2f, + (void *)&representor); + if (ret) { + ret = -EINVAL; + goto err; + } /* * Handler for "rep_based_pf" devarg. * Invoked as for ex: "-w 000:00:0d.0, * rep-based-pf= rep-is-pf=" */ - rte_kvargs_process(kvlist, BNXT_DEVARG_REP_FC_F2R, - bnxt_parse_devarg_rep_fc_f2r, - (void *)&representor); + ret = rte_kvargs_process(kvlist, BNXT_DEVARG_REP_FC_F2R, + bnxt_parse_devarg_rep_fc_f2r, + (void *)&representor); + if (ret) { + ret = -EINVAL; + goto err; + } } ret = rte_eth_dev_create(&pci_dev->device, name, @@ -6411,6 +6436,7 @@ static int bnxt_rep_port_probe(struct rte_pci_device *pci_dev, } + rte_kvargs_free(kvlist); return 0; err: @@ -6419,6 +6445,8 @@ static int bnxt_rep_port_probe(struct rte_pci_device *pci_dev, */ if (num_rep > 1) bnxt_pci_remove_dev_with_reps(backing_eth_dev); + rte_errno = -ret; + rte_kvargs_free(kvlist); return ret; } -- 2.21.1 (Apple Git-122.3)