graph_stats: do not use a possibly NULL Pointer

Message ID 20210524085850.16095-1-thierry.herbelot@6wind.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series graph_stats: do not use a possibly NULL Pointer |

Checks

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

Commit Message

Thierry Herbelot May 24, 2021, 8:58 a.m. UTC
  Use stats only after it was checked not to be NULL.

Fixes: af1ae8b6a32c9 ("graph: implement stats")
Cc: stable@dpdk.org
Cc: Jerin Jacob <jerinj@marvell.com>
Cc: Kiran Kumar K <kirankumark@marvell.com>

Signed-off-by: Thierry Herbelot <thierry.herbelot@6wind.com>
---
 lib/graph/graph_stats.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Jerin Jacob May 24, 2021, 9:23 a.m. UTC | #1
On Mon, May 24, 2021 at 2:28 PM Thierry Herbelot
<thierry.herbelot@6wind.com> wrote:
>
> Use stats only after it was checked not to be NULL.

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

With the above fix:

Acked-by: Jerin Jacob <jerinj@marvell.com>

>
> Fixes: af1ae8b6a32c9 ("graph: implement stats")
> Cc: stable@dpdk.org
> Cc: Jerin Jacob <jerinj@marvell.com>
> Cc: Kiran Kumar K <kirankumark@marvell.com>
>
> Signed-off-by: Thierry Herbelot <thierry.herbelot@6wind.com>
> ---
>  lib/graph/graph_stats.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/graph/graph_stats.c b/lib/graph/graph_stats.c
> index 125e08d73290..a52994f0f61e 100644
> --- a/lib/graph/graph_stats.c
> +++ b/lib/graph/graph_stats.c
> @@ -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
>
  

Patch

diff --git a/lib/graph/graph_stats.c b/lib/graph/graph_stats.c
index 125e08d73290..a52994f0f61e 100644
--- a/lib/graph/graph_stats.c
+++ b/lib/graph/graph_stats.c
@@ -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;