Skip to contentSkip to conversation

graph_stats: do not use a possibly NULL Pointer

PATCH In review Thierry Herbelot 3 participants 4 messages May 24, 2021 – May 25, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 graph_stats: do not use a possibly NULL Pointer

Use stats only after it was checked not to be NULL.

Fixes af1ae8b6a32c9 ("graph: implement stats")
Cc Jerin Jacob <[email protected]>
Cc Kiran Kumar K <[email protected]>
---
 lib/graph/graph_stats.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/graph/graph_stats.c +1 -1
index 125e08d73290..a52994f0f61e 100644
@@ -119,8 +119,8 @@ stats_mem_init(struct cluster *cluster,
 	cluster_node_size = RTE_ALIGN(cluster_node_size, RTE_CACHE_LINE_SIZE);
 
 	stats = realloc(NULL, sz);
-	memset(stats, 0, sz);
 	if (stats) {
+		memset(stats, 0, sz);
 		stats->fn = fn;
 		stats->cluster_node_size = cluster_node_size;
 		stats->max_nodes = 0;
Signature · 1 line
2.29.2
Acked-by on v1 1/1
#1 lore raw
Quoted 2 lines · Thierry Herbelot

Use stats only after it was checked not to be NULL.

Please change the subject to graph: ......

With the above fix:

Quoted 28 lines
Fixes af1ae8b6a32c9 ("graph: implement stats")
Cc Jerin Jacob <[email protected]>
Cc Kiran Kumar K <[email protected]>
---
 lib/graph/graph_stats.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/graph/graph_stats.c +1 -2
index 125e08d73290..a52994f0f61e 100644
@@ -119,8 +119,8 @@ stats_mem_init(struct cluster *cluster,
        cluster_node_size = RTE_ALIGN(cluster_node_size, RTE_CACHE_LINE_SIZE);
 
        stats = realloc(NULL, sz);
-       memset(stats, 0, sz);
        if (stats) {
+               memset(stats, 0, sz);
                stats->fn = fn;
                stats->cluster_node_size = cluster_node_size;
                stats->max_nodes = 0;
--

2.29.2

#2 lore raw

PATCH v2 1/1 graph: do not use a possibly NULL Pointer

In reply to Thierry Herbelot

Use stats only after it was checked not to be NULL.

Fixes af1ae8b6a32c9 ("graph: implement stats")
Cc Jerin Jacob <[email protected]>
Cc Kiran Kumar K <[email protected]>

--
V2: reword patch title

---
 lib/graph/graph_stats.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/graph/graph_stats.c +1 -1
index 125e08d73290..a52994f0f61e 100644
@@ -119,8 +119,8 @@ stats_mem_init(struct cluster *cluster,
 	cluster_node_size = RTE_ALIGN(cluster_node_size, RTE_CACHE_LINE_SIZE);
 
 	stats = realloc(NULL, sz);
-	memset(stats, 0, sz);
 	if (stats) {
+		memset(stats, 0, sz);
 		stats->fn = fn;
 		stats->cluster_node_size = cluster_node_size;
 		stats->max_nodes = 0;
Signature · 1 line
2.29.2
#3 lore raw

Re: [dpdk-dev] [PATCH v2] graph: do not use a possibly NULL Pointer

Quoted 20 lines · Thierry Herbelot

Use stats only after it was checked not to be NULL.

Fixes af1ae8b6a32c9 ("graph: implement stats")
Cc Jerin Jacob <[email protected]>
Cc Kiran Kumar K <[email protected]>

--
V2: reword patch title

---
 lib/graph/graph_stats.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/graph/graph_stats.c +0 -0
index 125e08d73290..a52994f0f61e 100644

lib/graph/graph_stats.c stats_mem_init(struct cluster *cluster, · line 126

Quoted 9 lines
lib/graph/graph_stats.c +1 -1
@@ -119,8 +119,8 @@ stats_mem_init(struct cluster *cluster,
        cluster_node_size = RTE_ALIGN(cluster_node_size, RTE_CACHE_LINE_SIZE);
 
        stats = realloc(NULL, sz);
-       memset(stats, 0, sz);
        if (stats) {
+               memset(stats, 0, sz);
                stats->fn = fn;
                stats->cluster_node_size = cluster_node_size;
                stats->max_nodes = 0;

Please update your patches status in patchwork when submitting new revisions.

Besides, the same fix had been posted by Min Hu:
http://patchwork.dpdk.org/project/dpdk/patch/[email protected]/

Signature · 1 line
David Marchand