Skip to contentSkip to conversation

test/graph: fix unused return value

PATCH Applied Zhirun Yan 3 participants 4 messages Jul 21, 2023 – Oct 17, 2023

lore
Share & tools
lore

Zhirun Yan

author
#0 lore raw

PATCH 1/1 test/graph: fix unused return value

Return value stored in "ret" but it may be overwritten before use. Add goto to return when meet an error. Issue reported by coverity scan.

Coverity issue: 395532

Fixes 15f483feec65 ("graph: fix model check in core binding")
---
 app/test/test_graph.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
app/test/test_graph.c +7 -4
index af90ac07ec..7995f67757 100644
@@ -740,13 +740,13 @@ test_graph_model_mcore_dispatch_core_bind_unbind(void)
 	ret = rte_graph_worker_model_set(RTE_GRAPH_MODEL_MCORE_DISPATCH);
 	if (ret != 0) {
 		printf("Set graph mcore dispatch model failed\n");
-		ret = -1;
+		goto fail;
 	}
 
 	ret = rte_graph_model_mcore_dispatch_core_bind(cloned_graph_id, worker_lcore);
 	if (ret != 0) {
 		printf("bind graph %d to lcore %u failed\n", graph_id, worker_lcore);
-		ret = -1;
+		goto fail;
 	}
 
 	graph = rte_graph_lookup("worker0-cloned-test2");
@@ -755,6 +755,7 @@ test_graph_model_mcore_dispatch_core_bind_unbind(void)
 		printf("bind graph %s(id:%d) with lcore %u failed\n",
 		       graph->name, graph->id, worker_lcore);
 		ret = -1;
+		goto fail;
 	}
 
 	rte_graph_model_mcore_dispatch_core_unbind(cloned_graph_id);
@@ -764,6 +765,7 @@ test_graph_model_mcore_dispatch_core_bind_unbind(void)
 		ret = -1;
 	}
 
+fail:
 	rte_graph_destroy(cloned_graph_id);
 
 	return ret;
@@ -781,7 +783,7 @@ test_graph_worker_model_set_get(void)
 	ret = rte_graph_worker_model_set(RTE_GRAPH_MODEL_MCORE_DISPATCH);
 	if (ret != 0) {
 		printf("Set graph mcore dispatch model failed\n");
-		ret = -1;
+		goto fail;
 	}
 
 	graph = rte_graph_lookup("worker0-cloned-test3");
@@ -790,9 +792,10 @@ test_graph_worker_model_set_get(void)
 		ret = -1;
 	}
 
+fail:
 	rte_graph_destroy(cloned_graph_id);
 
-	return 0;
+	return ret;
 }
 
 static int
Signature · 1 line
2.37.2
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Zhirun Yan

Return value stored in "ret" but it may be overwritten before use. Add goto to return when meet an error. Issue reported by coverity scan.

Coverity issue: 395532

Fixes 15f483feec65 ("graph: fix model check in core binding")
Quoted 64 lines
---
 app/test/test_graph.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
app/test/test_graph.c +7 -5
index af90ac07ec..7995f67757 100644
@@ -740,13 +740,13 @@ test_graph_model_mcore_dispatch_core_bind_unbind(void)
        ret = rte_graph_worker_model_set(RTE_GRAPH_MODEL_MCORE_DISPATCH);
        if (ret != 0) {
                printf("Set graph mcore dispatch model failed\n");
-               ret = -1;
+               goto fail;
        }
 
        ret = rte_graph_model_mcore_dispatch_core_bind(cloned_graph_id, worker_lcore);
        if (ret != 0) {
                printf("bind graph %d to lcore %u failed\n", graph_id, worker_lcore);
-               ret = -1;
+               goto fail;
        }
 
        graph = rte_graph_lookup("worker0-cloned-test2");
@@ -755,6 +755,7 @@ test_graph_model_mcore_dispatch_core_bind_unbind(void)
                printf("bind graph %s(id:%d) with lcore %u failed\n",
                       graph->name, graph->id, worker_lcore);
                ret = -1;
+               goto fail;
        }
 
        rte_graph_model_mcore_dispatch_core_unbind(cloned_graph_id);
@@ -764,6 +765,7 @@ test_graph_model_mcore_dispatch_core_bind_unbind(void)
                ret = -1;
        }
 
+fail:
        rte_graph_destroy(cloned_graph_id);
 
        return ret;
@@ -781,7 +783,7 @@ test_graph_worker_model_set_get(void)
        ret = rte_graph_worker_model_set(RTE_GRAPH_MODEL_MCORE_DISPATCH);
        if (ret != 0) {
                printf("Set graph mcore dispatch model failed\n");
-               ret = -1;
+               goto fail;
        }
 
        graph = rte_graph_lookup("worker0-cloned-test3");
@@ -790,9 +792,10 @@ test_graph_worker_model_set_get(void)
                ret = -1;
        }
 
+fail:
        rte_graph_destroy(cloned_graph_id);
 
-       return 0;
+       return ret;
 }
 
 static int
--

2.37.2

#2 lore raw
Quoted 14 lines

-----Original Message-----
From: Jerin Jacob <[email protected]>
Sent: Friday, July 21, 2023 8:51 PM
To: Yan, Zhirun <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v1] test/graph: fix unused return value

Quoted 4 lines · Zhirun Yan

Return value stored in "ret" but it may be overwritten before use. Add goto to return when meet an error. Issue reported by coverity scan.

Quoted 6 lines
Quoted 4 lines

Coverity issue: 395532

Fixes 15f483feec65 ("graph: fix model check in core binding")

A gentle ping for merge.