[1/2] examples/l2fwd-event: validate function return values

Message ID 20191121182718.7851-1-pbhagavatula@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: Jerin Jacob
Headers
Series [1/2] examples/l2fwd-event: validate function return values |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-compilation success Compile Testing PASS
ci/iol-mellanox-Performance fail Performance Testing issues
ci/Intel-compilation fail Compilation issues

Commit Message

Pavan Nikhilesh Bhagavatula Nov. 21, 2019, 6:27 p.m. UTC
  From: Pavan Nikhilesh <pbhagavatula@marvell.com>

Validate `rte_eth_link_get_nowait`, `rte_service_map_lcore_set` and
`rte_eth_dev_info_get` return values.

Coverity issue: 350600
Coverity issue: 350601
Coverity issue: 350602

Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
---
 examples/l2fwd-event/l2fwd_common.c |  6 +++++-
 examples/l2fwd-event/l2fwd_event.c  |  7 ++++---
 examples/l2fwd-event/main.c         | 10 +++++++++-
 3 files changed, 18 insertions(+), 5 deletions(-)
  

Comments

Jerin Jacob Nov. 26, 2019, 3:28 a.m. UTC | #1
On Fri, Nov 22, 2019 at 3:27 AM <pbhagavatula@marvell.com> wrote:
>
> From: Pavan Nikhilesh <pbhagavatula@marvell.com>
>
> Validate `rte_eth_link_get_nowait`, `rte_service_map_lcore_set` and
> `rte_eth_dev_info_get` return values.
>
> Coverity issue: 350600
> Coverity issue: 350601
> Coverity issue: 350602
>
> Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>

Applied to dpdk-next-eventdev/master. Thanks.


> ---
>  examples/l2fwd-event/l2fwd_common.c |  6 +++++-
>  examples/l2fwd-event/l2fwd_event.c  |  7 ++++---
>  examples/l2fwd-event/main.c         | 10 +++++++++-
>  3 files changed, 18 insertions(+), 5 deletions(-)
>
> diff --git a/examples/l2fwd-event/l2fwd_common.c b/examples/l2fwd-event/l2fwd_common.c
> index 4ba788550..0c069ec35 100644
> --- a/examples/l2fwd-event/l2fwd_common.c
> +++ b/examples/l2fwd-event/l2fwd_common.c
> @@ -41,7 +41,11 @@ l2fwd_event_init_ports(struct l2fwd_resources *rsrc)
>                 /* init port */
>                 printf("Initializing port %u... ", port_id);
>                 fflush(stdout);
> -               rte_eth_dev_info_get(port_id, &dev_info);
> +
> +               ret = rte_eth_dev_info_get(port_id, &dev_info);
> +               if (ret != 0)
> +                       rte_panic("Error during getting device (port %u) info: %s\n",
> +                                 port_id, strerror(-ret));
>                 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
>                         local_port_conf.txmode.offloads |=
>                                 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
> diff --git a/examples/l2fwd-event/l2fwd_event.c b/examples/l2fwd-event/l2fwd_event.c
> index c7782cbc5..0379c580d 100644
> --- a/examples/l2fwd-event/l2fwd_event.c
> +++ b/examples/l2fwd-event/l2fwd_event.c
> @@ -41,8 +41,9 @@ l2fwd_event_service_enable(uint32_t service_id)
>         /* Get the core which has least number of services running. */
>         while (slcore_count--) {
>                 /* Reset default mapping */
> -               rte_service_map_lcore_set(service_id,
> -                               slcore_array[slcore_count], 0);
> +               if (rte_service_map_lcore_set(service_id,
> +                                       slcore_array[slcore_count], 0) != 0)
> +                       return -ENOENT;
>                 service_count = rte_service_lcore_count_services(
>                                 slcore_array[slcore_count]);
>                 if (service_count < min_service_count) {
> @@ -50,7 +51,7 @@ l2fwd_event_service_enable(uint32_t service_id)
>                         min_service_count = service_count;
>                 }
>         }
> -       if (rte_service_map_lcore_set(service_id, slcore, 1))
> +       if (rte_service_map_lcore_set(service_id, slcore, 1) != 0)
>                 return -ENOENT;
>         rte_service_lcore_start(slcore);
>
> diff --git a/examples/l2fwd-event/main.c b/examples/l2fwd-event/main.c
> index 142c00e8f..89a6bb9a4 100644
> --- a/examples/l2fwd-event/main.c
> +++ b/examples/l2fwd-event/main.c
> @@ -234,6 +234,7 @@ check_all_ports_link_status(struct l2fwd_resources *rsrc,
>         uint16_t port_id;
>         uint8_t count, all_ports_up, print_flag = 0;
>         struct rte_eth_link link;
> +       int ret;
>
>         printf("\nChecking link status...");
>         fflush(stdout);
> @@ -247,7 +248,14 @@ check_all_ports_link_status(struct l2fwd_resources *rsrc,
>                         if ((port_mask & (1 << port_id)) == 0)
>                                 continue;
>                         memset(&link, 0, sizeof(link));
> -                       rte_eth_link_get_nowait(port_id, &link);
> +                       ret = rte_eth_link_get_nowait(port_id, &link);
> +                       if (ret < 0) {
> +                               all_ports_up = 0;
> +                               if (print_flag == 1)
> +                                       printf("Port %u link get failed: %s\n",
> +                                               port_id, rte_strerror(-ret));
> +                               continue;
> +                       }
>                         /* print link status if flag set */
>                         if (print_flag == 1) {
>                                 if (link.link_status)
> --
> 2.17.1
>
  

Patch

diff --git a/examples/l2fwd-event/l2fwd_common.c b/examples/l2fwd-event/l2fwd_common.c
index 4ba788550..0c069ec35 100644
--- a/examples/l2fwd-event/l2fwd_common.c
+++ b/examples/l2fwd-event/l2fwd_common.c
@@ -41,7 +41,11 @@  l2fwd_event_init_ports(struct l2fwd_resources *rsrc)
 		/* init port */
 		printf("Initializing port %u... ", port_id);
 		fflush(stdout);
-		rte_eth_dev_info_get(port_id, &dev_info);
+
+		ret = rte_eth_dev_info_get(port_id, &dev_info);
+		if (ret != 0)
+			rte_panic("Error during getting device (port %u) info: %s\n",
+				  port_id, strerror(-ret));
 		if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
 			local_port_conf.txmode.offloads |=
 				DEV_TX_OFFLOAD_MBUF_FAST_FREE;
diff --git a/examples/l2fwd-event/l2fwd_event.c b/examples/l2fwd-event/l2fwd_event.c
index c7782cbc5..0379c580d 100644
--- a/examples/l2fwd-event/l2fwd_event.c
+++ b/examples/l2fwd-event/l2fwd_event.c
@@ -41,8 +41,9 @@  l2fwd_event_service_enable(uint32_t service_id)
 	/* Get the core which has least number of services running. */
 	while (slcore_count--) {
 		/* Reset default mapping */
-		rte_service_map_lcore_set(service_id,
-				slcore_array[slcore_count], 0);
+		if (rte_service_map_lcore_set(service_id,
+					slcore_array[slcore_count], 0) != 0)
+			return -ENOENT;
 		service_count = rte_service_lcore_count_services(
 				slcore_array[slcore_count]);
 		if (service_count < min_service_count) {
@@ -50,7 +51,7 @@  l2fwd_event_service_enable(uint32_t service_id)
 			min_service_count = service_count;
 		}
 	}
-	if (rte_service_map_lcore_set(service_id, slcore, 1))
+	if (rte_service_map_lcore_set(service_id, slcore, 1) != 0)
 		return -ENOENT;
 	rte_service_lcore_start(slcore);
 
diff --git a/examples/l2fwd-event/main.c b/examples/l2fwd-event/main.c
index 142c00e8f..89a6bb9a4 100644
--- a/examples/l2fwd-event/main.c
+++ b/examples/l2fwd-event/main.c
@@ -234,6 +234,7 @@  check_all_ports_link_status(struct l2fwd_resources *rsrc,
 	uint16_t port_id;
 	uint8_t count, all_ports_up, print_flag = 0;
 	struct rte_eth_link link;
+	int ret;
 
 	printf("\nChecking link status...");
 	fflush(stdout);
@@ -247,7 +248,14 @@  check_all_ports_link_status(struct l2fwd_resources *rsrc,
 			if ((port_mask & (1 << port_id)) == 0)
 				continue;
 			memset(&link, 0, sizeof(link));
-			rte_eth_link_get_nowait(port_id, &link);
+			ret = rte_eth_link_get_nowait(port_id, &link);
+			if (ret < 0) {
+				all_ports_up = 0;
+				if (print_flag == 1)
+					printf("Port %u link get failed: %s\n",
+						port_id, rte_strerror(-ret));
+				continue;
+			}
 			/* print link status if flag set */
 			if (print_flag == 1) {
 				if (link.link_status)