net/bnxt: fix resource leak
authorAjit Khaparde <ajit.khaparde@broadcom.com>
Tue, 20 Oct 2020 23:24:28 +0000 (16:24 -0700)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 3 Nov 2020 22:24:26 +0000 (23:24 +0100)
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")
Cc: stable@dpdk.org
Signed-off-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
Reviewed-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
drivers/net/bnxt/bnxt_ethdev.c

index e2b66c4..8025e33 100644 (file)
@@ -6302,7 +6302,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) {
@@ -6356,49 +6356,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=<pf index> rep-is-pf=<VF=0 or PF=1>"
                         */
-                       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=<pf index> rep-is-pf=<VF=0 or PF=1>"
                         */
-                       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=<pf index> rep-is-pf=<VF=0 or PF=1>"
                         */
-                       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=<pf index> rep-is-pf=<VF=0 or PF=1>"
                         */
-                       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=<pf index> rep-is-pf=<VF=0 or PF=1>"
                         */
-                       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=<pf index> rep-is-pf=<VF=0 or PF=1>"
                         */
-                       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,
@@ -6428,6 +6453,7 @@ static int bnxt_rep_port_probe(struct rte_pci_device *pci_dev,
 
        }
 
+       rte_kvargs_free(kvlist);
        return 0;
 
 err:
@@ -6436,6 +6462,8 @@ err:
         */
        if (num_rep > 1)
                bnxt_pci_remove_dev_with_reps(backing_eth_dev);
+       rte_errno = -ret;
+       rte_kvargs_free(kvlist);
 
        return ret;
 }