[v3] net/mlx5: fix matcher object memory leak

Message ID 20240702201450.349991-1-mahmoudmatook.mm@gmail.com (mailing list archive)
State Accepted, archived
Delegated to: Raslan Darawsheh
Headers
Series [v3] net/mlx5: fix matcher object memory leak |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-abi-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS

Commit Message

Mahmoud Matook July 2, 2024, 8:14 p.m. UTC
This makes sure that the allocated matcher object is freed
for all branches that return NULL.

Coverity issue: 426424
Fixes: 27d171b88031 ("net/mlx5: abstract flow action and enable reconfigure")
Cc: mkashani@nvidia.com

Signed-off-by: Mahmoud Maatuq <mahmoudmatook.mm@gmail.com>
---
v3:
* changed commit message.
* fixed typos
v2:
* fixed Fixes and Cc tags.
---
 drivers/net/mlx5/mlx5_flow_dv.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

--
2.43.0
  

Comments

Bing Zhao July 3, 2024, 8 a.m. UTC | #1
Hi,


> -----Original Message-----
> From: Mahmoud Maatuq <mahmoudmatook.mm@gmail.com>
> Sent: Wednesday, July 3, 2024 4:15 AM
> To: Dariusz Sosnowski <dsosnowski@nvidia.com>; Slava Ovsiienko
> <viacheslavo@nvidia.com>; Bing Zhao <bingz@nvidia.com>; Ori Kam
> <orika@nvidia.com>; Suanming Mou <suanmingm@nvidia.com>; Matan Azrad
> <matan@nvidia.com>; Maayan Kashani <mkashani@nvidia.com>
> Cc: dev@dpdk.org; Mahmoud Maatuq <mahmoudmatook.mm@gmail.com>
> Subject: [PATCH v3] net/mlx5: fix matcher object memory leak
> 
> External email: Use caution opening links or attachments
> 
> 
> This makes sure that the allocated matcher object is freed for all
> branches that return NULL.
> 
> Coverity issue: 426424
> Fixes: 27d171b88031 ("net/mlx5: abstract flow action and enable
> reconfigure")
> Cc: mkashani@nvidia.com
> 
> Signed-off-by: Mahmoud Maatuq <mahmoudmatook.mm@gmail.com>
> ---
> v3:
> * changed commit message.
> * fixed typos
> v2:
> * fixed Fixes and Cc tags.
> ---
>  drivers/net/mlx5/mlx5_flow_dv.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/mlx5/mlx5_flow_dv.c
> b/drivers/net/mlx5/mlx5_flow_dv.c index d46beffd4c..8a0d58cb05 100644
> --- a/drivers/net/mlx5/mlx5_flow_dv.c
> +++ b/drivers/net/mlx5/mlx5_flow_dv.c
> @@ -12010,9 +12010,12 @@ flow_matcher_create_cb(void *tool_ctx, void
> *cb_ctx)
>                 items = *((const struct rte_flow_item **)(ctx->data2));
>                 resource->matcher_object = mlx5dr_bwc_matcher_create
>                                 (resource->group->tbl, resource->priority,
> items);
> -               if (!(resource->matcher_object))
> +               if (!resource->matcher_object) {
> +                       mlx5_free(resource);
>                         return NULL;
> +               }
>  #else
> +               mlx5_free(resource);
>                 return NULL;
>  #endif
>         }
> --
> 2.43.0

Acked-by: Bing Zhao <bingz@nvidia.com>
  
Dariusz Sosnowski July 3, 2024, 8:08 a.m. UTC | #2
Hi,

> -----Original Message-----
> From: Bing Zhao <bingz@nvidia.com>
> Sent: Wednesday, July 3, 2024 10:00
> To: Mahmoud Maatuq <mahmoudmatook.mm@gmail.com>; Dariusz
> Sosnowski <dsosnowski@nvidia.com>; Slava Ovsiienko
> <viacheslavo@nvidia.com>; Ori Kam <orika@nvidia.com>; Suanming Mou
> <suanmingm@nvidia.com>; Matan Azrad <matan@nvidia.com>; Maayan
> Kashani <mkashani@nvidia.com>
> Cc: dev@dpdk.org
> Subject: RE: [PATCH v3] net/mlx5: fix matcher object memory leak
> 
> Hi,
> 
> 
> > -----Original Message-----
> > From: Mahmoud Maatuq <mahmoudmatook.mm@gmail.com>
> > Sent: Wednesday, July 3, 2024 4:15 AM
> > To: Dariusz Sosnowski <dsosnowski@nvidia.com>; Slava Ovsiienko
> > <viacheslavo@nvidia.com>; Bing Zhao <bingz@nvidia.com>; Ori Kam
> > <orika@nvidia.com>; Suanming Mou <suanmingm@nvidia.com>; Matan
> Azrad
> > <matan@nvidia.com>; Maayan Kashani <mkashani@nvidia.com>
> > Cc: dev@dpdk.org; Mahmoud Maatuq <mahmoudmatook.mm@gmail.com>
> > Subject: [PATCH v3] net/mlx5: fix matcher object memory leak
> >
> > External email: Use caution opening links or attachments
> >
> >
> > This makes sure that the allocated matcher object is freed for all
> > branches that return NULL.
> >
> > Coverity issue: 426424
> > Fixes: 27d171b88031 ("net/mlx5: abstract flow action and enable
> > reconfigure")
> > Cc: mkashani@nvidia.com
> >
> > Signed-off-by: Mahmoud Maatuq <mahmoudmatook.mm@gmail.com>
> > ---
> > v3:
> > * changed commit message.
> > * fixed typos
> > v2:
> > * fixed Fixes and Cc tags.
> > ---
> >  drivers/net/mlx5/mlx5_flow_dv.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/mlx5/mlx5_flow_dv.c
> > b/drivers/net/mlx5/mlx5_flow_dv.c index d46beffd4c..8a0d58cb05 100644
> > --- a/drivers/net/mlx5/mlx5_flow_dv.c
> > +++ b/drivers/net/mlx5/mlx5_flow_dv.c
> > @@ -12010,9 +12010,12 @@ flow_matcher_create_cb(void *tool_ctx, void
> > *cb_ctx)
> >                 items = *((const struct rte_flow_item **)(ctx->data2));
> >                 resource->matcher_object = mlx5dr_bwc_matcher_create
> >                                 (resource->group->tbl,
> > resource->priority, items);
> > -               if (!(resource->matcher_object))
> > +               if (!resource->matcher_object) {
> > +                       mlx5_free(resource);
> >                         return NULL;
> > +               }
> >  #else
> > +               mlx5_free(resource);
> >                 return NULL;
> >  #endif
> >         }
> > --
> > 2.43.0
> 
> Acked-by: Bing Zhao <bingz@nvidia.com>

Thank you for all the changes and the patch!

Acked-by: Dariusz Sosnowski <dsosnowski@nvidia.com>

Best regards,
Dariusz Sosnowski
  
Raslan Darawsheh July 4, 2024, 10:34 a.m. UTC | #3
Hi,

From: Mahmoud Maatuq <mahmoudmatook.mm@gmail.com>
Sent: Tuesday, July 2, 2024 11:14 PM
To: Dariusz Sosnowski; Slava Ovsiienko; Bing Zhao; Ori Kam; Suanming Mou; Matan Azrad; Maayan Kashani
Cc: dev@dpdk.org; Mahmoud Maatuq
Subject: [PATCH v3] net/mlx5: fix matcher object memory leak

This makes sure that the allocated matcher object is freed
for all branches that return NULL.

Coverity issue: 426424
Fixes: 27d171b88031 ("net/mlx5: abstract flow action and enable reconfigure")
Cc: mkashani@nvidia.com

Signed-off-by: Mahmoud Maatuq <mahmoudmatook.mm@gmail.com>

Patch applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh
  

Patch

diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
index d46beffd4c..8a0d58cb05 100644
--- a/drivers/net/mlx5/mlx5_flow_dv.c
+++ b/drivers/net/mlx5/mlx5_flow_dv.c
@@ -12010,9 +12010,12 @@  flow_matcher_create_cb(void *tool_ctx, void *cb_ctx)
 		items = *((const struct rte_flow_item **)(ctx->data2));
 		resource->matcher_object = mlx5dr_bwc_matcher_create
 				(resource->group->tbl, resource->priority, items);
-		if (!(resource->matcher_object))
+		if (!resource->matcher_object) {
+			mlx5_free(resource);
 			return NULL;
+		}
 #else
+		mlx5_free(resource);
 		return NULL;
 #endif
 	}