fix ethdev port id validation
[dpdk.git] / examples / bbdev_app / main.c
index e779db2..254cc06 100644 (file)
@@ -616,8 +616,16 @@ print_stats(struct stats_lcore_params *stats_lcore)
                                        xstats[i].value);
        }
 
+       ret = rte_bbdev_stats_get(bbdev_id, &bbstats);
+       if (ret < 0) {
+               free(xstats);
+               free(xstats_names);
+               rte_exit(EXIT_FAILURE,
+                               "ERROR(%d): Failure to get BBDEV %u statistics\n",
+                               ret, bbdev_id);
+       }
+
        printf("\nBBDEV STATISTICS:\n=================\n");
-       rte_bbdev_stats_get(bbdev_id, &bbstats);
        printf("BBDEV %u: %s enqueue count:\t\t%"PRIu64"\n",
                        bbdev_id, stats_border,
                        bbstats.enqueued_count);
@@ -1009,7 +1017,7 @@ int
 main(int argc, char **argv)
 {
        int ret;
-       unsigned int nb_bbdevs, nb_ports, flags, lcore_id;
+       unsigned int nb_bbdevs, flags, lcore_id;
        void *sigret;
        struct app_config_params app_params = def_app_config;
        struct rte_mempool *ethdev_mbuf_mempool, *bbdev_mbuf_mempool;
@@ -1071,12 +1079,10 @@ main(int argc, char **argv)
                                nb_bbdevs, app_params.bbdev_id);
        printf("Number of bbdevs detected: %d\n", nb_bbdevs);
 
-       /* Get the number of available ethdev devices */
-       nb_ports = rte_eth_dev_count();
-       if (nb_ports <= app_params.port_id)
+       if (!rte_eth_dev_is_valid_port(app_params.port_id))
                rte_exit(EXIT_FAILURE,
-                               "%u ports detected, cannot use port with ID %u!\n",
-                               nb_ports, app_params.port_id);
+                               "cannot use port with ID %u!\n",
+                               app_params.port_id);
 
        /* create the mbuf mempool for ethdev pkts */
        ethdev_mbuf_mempool = rte_pktmbuf_pool_create("ethdev_mbuf_pool",