net/i40e: fix memory leak if VF init fails
PATCH 1/1 net/i40e: fix memory leak if VF init fails
--- drivers/net/i40e/i40e_ethdev_vf.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/i40e/i40e_ethdev_vf.c +2 -0
@@ -1317,6 +1317,8 @@ i40evf_init_vf(struct rte_eth_dev *dev) err_alloc:rte_free (vf->vf_res); +rte_free (vf->aq_resp); + vf->vsi_res =NULL ; err_aq:i40e_shutdown_adminq (hw);/* ignore error */ err:
Signature · 1 line
2.7.4
PATCH v2 1/1 net/i40e: fix memory leak if VF init fails
---
v2 change:
- free aq_resp at err_aq
drivers/net/i40e/i40e_ethdev_vf.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/i40e/i40e_ethdev_vf.c +2 -0
@@ -1317,7 +1317,9 @@ i40evf_init_vf(struct rte_eth_dev *dev) err_alloc:rte_free (vf->vf_res); + vf->vsi_res =NULL ; err_aq: +rte_free (vf->aq_resp);i40e_shutdown_adminq (hw);/* ignore error */ err:return -1 ;
Signature · 1 line
2.7.4
PATCH v3 1/1 net/i40e: fix memory leak if VF init fails
---
v3 change:
- add new err branch to free aq_resp
- fix indent
v2 change:
- free aq_resp at err_aq
drivers/net/i40e/i40e_ethdev_vf.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/net/i40e/i40e_ethdev_vf.c +8 -5
@@ -1249,29 +1249,29 @@ i40evf_init_vf(struct rte_eth_dev *dev)/* VF reset, shutdown admin queue and initialize again */ if (i40e_shutdown_adminq (hw) !=I40E_SUCCESS ) {PMD_INIT_LOG (ERR ,"i40e_shutdown_adminq failed" ); -return -1 ; + goto err; }i40e_init_adminq_parameter (hw);if (i40e_init_adminq (hw) !=I40E_SUCCESS ) {PMD_INIT_LOG (ERR ,"init_adminq failed" ); -return -1 ; + goto err; } vf->aq_resp =rte_zmalloc ("vf_aq_resp" ,I40E_AQ_BUF_SZ ,0 );if (!vf->aq_resp) {PMD_INIT_LOG (ERR ,"unable to allocate vf_aq_resp memory" ); - goto err_aq; + goto err_aq; }if (i40evf_check_api_version (dev) !=0 ) {PMD_INIT_LOG (ERR ,"check_api version failed" ); - goto err_aq; + goto err_api; } bufsz =sizeof (struct virtchnl_vf_resource ) + (I40E_MAX_VF_VSI *sizeof (struct virtchnl_vsi_resource )); vf->vf_res =rte_zmalloc ("vf_res" , bufsz,0 );if (!vf->vf_res) {PMD_INIT_LOG (ERR ,"unable to allocate vf_res memory" ); - goto err_aq; + goto err_api; }if (i40evf_get_vf_resource (dev) !=0 ) {
@@ -1317,6 +1317,9 @@ i40evf_init_vf(struct rte_eth_dev *dev) err_alloc:rte_free (vf->vf_res); + vf->vsi_res =NULL ; +err_api: +rte_free (vf->aq_resp); err_aq:i40e_shutdown_adminq (hw);/* ignore error */ err:
Signature · 1 line
2.7.4
Quoted 26 lines
-----Original Message-----
From: Wu, Jingjing
Sent: Wednesday, September 13, 2017 3:24 AM
To: Xing, Beilei <[email protected]>
Cc: [email protected]; Wu, Jingjing <[email protected]>; [email protected]
Subject: [PATCH v2] net/i40e: fix memory leak if VF init failsFixes 4861cde46116 ("i40e: new poll mode driver")Signed-off-by Jingjing Wu <[email protected]>---
v2 change:
- freeaq_respaterr_aqdrivers/net/i40e/i40e_ethdev_vf.c | 2 ++ 1 file changed, 2 insertions(+)drivers/net/i40e/i40e_ethdev_vf.c +0
-0
drivers/net/i40e/i40e_ethdev_vf.c i40evf_init_vf(struct rte_eth_dev *dev) · line 1322
Quoted 6 lines
drivers/net/i40e/i40e_ethdev_vf.c +2
-0@@ -1317,7 +1317,9 @@ i40evf_init_vf(struct rte_eth_dev *dev) err_alloc:rte_free (vf->vf_res); + vf->vsi_res =NULL ; err_aq: +rte_free (vf->aq_resp);
Seems it's inappropriate to free aq_resp here, if reset NIC failed, vf->aq_resp is not allocated yet.
/* Reset VF and wait until it's complete */
if (i40evf_reset_vf(hw)) {
PMD_INIT_LOG(ERR, "reset NIC failed");
goto err_aq;
}How about adding a new error branch?
Quoted 5 lines
drivers/net/i40e/i40e_ethdev_vf.c +0
-1i40e_shutdown_adminq (hw);/* ignore error */ err:return -1 ; --2.7.4
Quoted 45 lines
-----Original Message-----
From: Xing, Beilei
Sent: Wednesday, September 13, 2017 11:23 AM
To: Wu, Jingjing <[email protected]>
Cc: [email protected]; [email protected]
Subject: RE: [PATCH v2] net/i40e: fix memory leak if VF init failsQuoted 24 lines
-----Original Message-----
From: Wu, Jingjing
Sent: Wednesday, September 13, 2017 3:24 AM
To: Xing, Beilei <[email protected]>
Cc: [email protected]; Wu, Jingjing <[email protected]>; [email protected]
Subject: [PATCH v2] net/i40e: fix memory leak if VF init failsFixes 4861cde46116 ("i40e: new poll mode driver")Signed-off-by Jingjing Wu <[email protected]>---
v2 change:
- freeaq_respaterr_aqdrivers/net/i40e/i40e_ethdev_vf.c | 2 ++ 1 file changed, 2 insertions(+)drivers/net/i40e/i40e_ethdev_vf.c +0
-0drivers/net/i40e/i40e_ethdev_vf.c i40evf_init_vf(struct rte_eth_dev *dev) · line 1322
Quoted 6 lines
drivers/net/i40e/i40e_ethdev_vf.c +2
-0@@ -1317,7 +1317,9 @@ i40evf_init_vf(struct rte_eth_dev *dev) err_alloc:rte_free (vf->vf_res); + vf->vsi_res =NULL ; err_aq: +rte_free (vf->aq_resp);Seems it's inappropriate to free
aq_resphere, if reset NIC failed,vf->aq_respis not allocated yet.
Quoted 7 lines
/* Reset VF and wait until it's complete */
if (i40evf_reset_vf(hw)) { PMD_INIT_LOG(ERR, "reset NIC failed"); goto err_aq; }How about adding a new error branch?
Yes, a new version will be sent.
Thanks
Jingjing
Quoted 9 lines
-----Original Message-----
From: Wu, Jingjing
Sent: Wednesday, September 13, 2017 7:54 AM
To: Xing, Beilei <[email protected]>
Cc: [email protected]; Wu, Jingjing <[email protected]>; [email protected]
Subject: [PATCH v3] net/i40e: fix memory leak if VF init fails
Quoted 4 lines
Fixes 4861cde46116 ("i40e: new poll mode driver")Signed-off-by Jingjing Wu <[email protected]>
Ferruh Yigit
AppliedQuoted 9 lines · Beilei
Quoted 9 lines
-----Original Message-----
From: Wu, Jingjing
Sent: Wednesday, September 13, 2017 7:54 AM
To: Xing, Beilei <[email protected]>
Cc: [email protected]; Wu, Jingjing <[email protected]>; [email protected]
Subject: [PATCH v3] net/i40e: fix memory leak if VF init fails
Quoted 6 lines
Quoted 4 lines
Fixes 4861cde46116 ("i40e: new poll mode driver")Signed-off-by Jingjing Wu <[email protected]>Acked-by Beilei Xing <[email protected]>
Applied to dpdk-next-net/master, thanks.