net/octeontx: fix memory leak of MAC address table

Message ID 20200129091704.18217-1-skori@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: Jerin Jacob
Headers
Series net/octeontx: fix memory leak of MAC address table |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-nxp-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS
ci/travis-robot success Travis build: passed
ci/Intel-compilation fail apply issues

Commit Message

Sunil Kumar Kori Jan. 29, 2020, 9:17 a.m. UTC
  MAC address table is allocated during octeontx device create and
same is used to maintain list of MAC address associated to port.
This table is not getting freed niether in case of error nor during
graceful shutdown of port.

Patch fixes memory required memory for both the cases as mentioned.

Fixes: f18b146c498d ("net/octeontx: create ethdev ports")

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
 drivers/net/octeontx/octeontx_ethdev.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
  

Comments

Harman Kalra Jan. 29, 2020, 12:28 p.m. UTC | #1
On Wed, Jan 29, 2020 at 02:47:04PM +0530, Sunil Kumar Kori wrote:
> MAC address table is allocated during octeontx device create and
> same is used to maintain list of MAC address associated to port.
> This table is not getting freed niether in case of error nor during
> graceful shutdown of port.
> 
> Patch fixes memory required memory for both the cases as mentioned.
> 
> Fixes: f18b146c498d ("net/octeontx: create ethdev ports")
> 
> Signed-off-by: Sunil Kumar Kori <skori@marvell.com>

Acked-by: Harman Kalra <hkalra@marvell.com>

> ---
>  drivers/net/octeontx/octeontx_ethdev.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/octeontx/octeontx_ethdev.c b/drivers/net/octeontx/octeontx_ethdev.c
> index e23162d8a..40d9d67da 100644
> --- a/drivers/net/octeontx/octeontx_ethdev.c
> +++ b/drivers/net/octeontx/octeontx_ethdev.c
> @@ -351,6 +351,10 @@ octeontx_dev_close(struct rte_eth_dev *dev)
>  		rte_free(txq);
>  	}
>  
> +	/* Free MAC address table */
> +	rte_free(dev->data->mac_addrs);
> +	dev->data->mac_addrs = NULL;
> +
>  	dev->tx_pkt_burst = NULL;
>  	dev->rx_pkt_burst = NULL;
>  }
> @@ -1143,7 +1147,7 @@ octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev,
>  		octeontx_log_err("eth_dev->port_id (%d) is diff to orig (%d)",
>  				data->port_id, nic->port_id);
>  		res = -EINVAL;
> -		goto err;
> +		goto free_mac_addrs;
>  	}
>  
>  	/* Update port_id mac to eth_dev */
> @@ -1162,6 +1166,8 @@ octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev,
>  	rte_eth_dev_probing_finish(eth_dev);
>  	return data->port_id;
>  
> +free_mac_addrs:
> +	rte_free(data->mac_addrs);
>  err:
>  	if (nic)
>  		octeontx_port_close(nic);
> -- 
> 2.17.1
>
  
Jerin Jacob Feb. 3, 2020, 9:54 a.m. UTC | #2
On Wed, Jan 29, 2020 at 5:58 PM Harman Kalra <hkalra@marvell.com> wrote:
>
> On Wed, Jan 29, 2020 at 02:47:04PM +0530, Sunil Kumar Kori wrote:
> > MAC address table is allocated during octeontx device create and
> > same is used to maintain list of MAC address associated to port.
> > This table is not getting freed niether in case of error nor during
> > graceful shutdown of port.
> >
> > Patch fixes memory required memory for both the cases as mentioned.
> >
> > Fixes: f18b146c498d ("net/octeontx: create ethdev ports")

Cc: stable@dpdk.org

> >
> > Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
>
> Acked-by: Harman Kalra <hkalra@marvell.com>

Applied to dpdk-next-net-mrvl/master. Thanks


>
> > ---
> >  drivers/net/octeontx/octeontx_ethdev.c | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/octeontx/octeontx_ethdev.c b/drivers/net/octeontx/octeontx_ethdev.c
> > index e23162d8a..40d9d67da 100644
> > --- a/drivers/net/octeontx/octeontx_ethdev.c
> > +++ b/drivers/net/octeontx/octeontx_ethdev.c
> > @@ -351,6 +351,10 @@ octeontx_dev_close(struct rte_eth_dev *dev)
> >               rte_free(txq);
> >       }
> >
> > +     /* Free MAC address table */
> > +     rte_free(dev->data->mac_addrs);
> > +     dev->data->mac_addrs = NULL;
> > +
> >       dev->tx_pkt_burst = NULL;
> >       dev->rx_pkt_burst = NULL;
> >  }
> > @@ -1143,7 +1147,7 @@ octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev,
> >               octeontx_log_err("eth_dev->port_id (%d) is diff to orig (%d)",
> >                               data->port_id, nic->port_id);
> >               res = -EINVAL;
> > -             goto err;
> > +             goto free_mac_addrs;
> >       }
> >
> >       /* Update port_id mac to eth_dev */
> > @@ -1162,6 +1166,8 @@ octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev,
> >       rte_eth_dev_probing_finish(eth_dev);
> >       return data->port_id;
> >
> > +free_mac_addrs:
> > +     rte_free(data->mac_addrs);
> >  err:
> >       if (nic)
> >               octeontx_port_close(nic);
> > --
> > 2.17.1
> >
  

Patch

diff --git a/drivers/net/octeontx/octeontx_ethdev.c b/drivers/net/octeontx/octeontx_ethdev.c
index e23162d8a..40d9d67da 100644
--- a/drivers/net/octeontx/octeontx_ethdev.c
+++ b/drivers/net/octeontx/octeontx_ethdev.c
@@ -351,6 +351,10 @@  octeontx_dev_close(struct rte_eth_dev *dev)
 		rte_free(txq);
 	}
 
+	/* Free MAC address table */
+	rte_free(dev->data->mac_addrs);
+	dev->data->mac_addrs = NULL;
+
 	dev->tx_pkt_burst = NULL;
 	dev->rx_pkt_burst = NULL;
 }
@@ -1143,7 +1147,7 @@  octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev,
 		octeontx_log_err("eth_dev->port_id (%d) is diff to orig (%d)",
 				data->port_id, nic->port_id);
 		res = -EINVAL;
-		goto err;
+		goto free_mac_addrs;
 	}
 
 	/* Update port_id mac to eth_dev */
@@ -1162,6 +1166,8 @@  octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev,
 	rte_eth_dev_probing_finish(eth_dev);
 	return data->port_id;
 
+free_mac_addrs:
+	rte_free(data->mac_addrs);
 err:
 	if (nic)
 		octeontx_port_close(nic);