Skip to contentSkip to conversation

examples/ioat: fix unchecked return value

PATCH New Ciara Power 3 participants 4 messages Feb 4, 2020 – Feb 13, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 examples/ioat: fix unchecked return value

The return value of the get link function call was not checked, and could return a negative value indicating a failure. If the return value is not 0 for success, the loop continues with the next port.

To avoid a slight name clash with the new ret variable, the existing retval variable is renamed to link_status, to better represent its use.

Coverity issue: 350348

Fixes c8e6ceecebc1 ("examples/ioat: add new sample app for ioat driver")
---
 examples/ioat/ioatfwd.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
examples/ioat/ioatfwd.c +9 -4
index e9117718f..99ecc0fde 100644
@@ -697,7 +697,7 @@ check_link_status(uint32_t port_mask)
 {
 	uint16_t portid;
 	struct rte_eth_link link;
-	int retval = 0;
+	int ret, link_status = 0;
 
 	printf("\nChecking link status\n");
 	RTE_ETH_FOREACH_DEV(portid) {
@@ -705,7 +705,12 @@ check_link_status(uint32_t port_mask)
 			continue;
 
 		memset(&link, 0, sizeof(link));
-		rte_eth_link_get(portid, &link);
+		ret = rte_eth_link_get(portid, &link);
+		if (ret < 0) {
+			printf("Port %u link get failed: err=%d\n",
+					portid, ret);
+			continue;
+		}
 
 		/* Print link status */
 		if (link.link_status) {
@@ -714,11 +719,11 @@ check_link_status(uint32_t port_mask)
 				portid, link.link_speed,
 				(link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
 				("full-duplex") : ("half-duplex\n"));
-			retval = 1;
+			link_status = 1;
 		} else
 			printf("Port %d Link Down\n", portid);
 	}
-	return retval;
+	return link_status;
 }
 
 static void
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/1 examples/ioat: fix invalid link status check

The return value of the get link function call was not checked, and could return a negative value indicating a failure. This meant the link_status of the link being checked is invalid, because the link was not filled with data. The return value is now checked, and if the return value is not 0 for success, the loop continues with the next port.

To avoid confusion between variable names, the existing retval variable is renamed to link_status, to better represent its use.

Coverity issue: 350348

Fixes c8e6ceecebc1 ("examples/ioat: add new sample app for ioat driver")

---
v2:
- Changed commit log subject and description
- Rebased onto master

---
 examples/ioat/ioatfwd.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
examples/ioat/ioatfwd.c +9 -4
index e9117718f..99ecc0fde 100644
@@ -697,7 +697,7 @@ check_link_status(uint32_t port_mask)
 {
 	uint16_t portid;
 	struct rte_eth_link link;
-	int retval = 0;
+	int ret, link_status = 0;
 
 	printf("\nChecking link status\n");
 	RTE_ETH_FOREACH_DEV(portid) {
@@ -705,7 +705,12 @@ check_link_status(uint32_t port_mask)
 			continue;
 
 		memset(&link, 0, sizeof(link));
-		rte_eth_link_get(portid, &link);
+		ret = rte_eth_link_get(portid, &link);
+		if (ret < 0) {
+			printf("Port %u link get failed: err=%d\n",
+					portid, ret);
+			continue;
+		}
 
 		/* Print link status */
 		if (link.link_status) {
@@ -714,11 +719,11 @@ check_link_status(uint32_t port_mask)
 				portid, link.link_speed,
 				(link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
 				("full-duplex") : ("half-duplex\n"));
-			retval = 1;
+			link_status = 1;
 		} else
 			printf("Port %d Link Down\n", portid);
 	}
-	return retval;
+	return link_status;
 }
 
 static void
Signature · 1 line
2.17.1
Acked-by on v2 1/1
#2 lore raw

Re: [dpdk-dev] [PATCH v2] examples/ioat: fix invalid link status check

Quoted 9 lines · Ciara Power

The return value of the get link function call was not checked, and could return a negative value indicating a failure. This meant the link_status of the link being checked is invalid, because the link was not filled with data. The return value is now checked, and if the return value is not 0 for success, the loop continues with the next port.

To avoid confusion between variable names, the existing retval variable is renamed to link_status, to better represent its use.

Quoted 7 lines

Coverity issue: 350348

Fixes c8e6ceecebc1 ("examples/ioat: add new sample app for ioat driver")
Acked-by Bruce Richardson on v2 1/1 Applied
#3 lore raw

Re: [dpdk-dev] [PATCH v2] examples/ioat: fix invalid link status check

In reply to Ciara Power
Quoted 7 lines · Ciara Power

The return value of the get link function call was not checked, and could return a negative value indicating a failure. This meant the link_status of the link being checked is invalid, because the link was not filled with data. The return value is now checked, and if the return value is not 0 for success, the loop continues with the next port.

Quoted 8 lines

To avoid confusion between variable names, the existing retval variable is renamed to link_status, to better represent its use.

Coverity issue: 350348

Fixes c8e6ceecebc1 ("examples/ioat: add new sample app for ioat driver")

Applied, thanks.

--
David Marchand