i40e: prevent memory leak in i40e_setup_macvlans
diff mbox series

Message ID 20190925154831.19044-1-navid.emamdoost@gmail.com
State Accepted
Delegated to: Jeff Kirsher
Headers show
Series
  • i40e: prevent memory leak in i40e_setup_macvlans
Related show

Commit Message

Navid Emamdoost Sept. 25, 2019, 3:48 p.m. UTC
In i40e_setup_macvlans if i40e_setup_channel fails the allocated memory
for ch should be released.

Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
 drivers/net/ethernet/intel/i40e/i40e_main.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Markus Elfring Sept. 27, 2019, 3:04 p.m. UTC | #1
> In i40e_setup_macvlans if i40e_setup_channel fails the allocated memory
> for ch should be released.

I suggest to improve also this change description.


> +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
> @@ -7168,6 +7168,7 @@ static int i40e_setup_macvlans(struct i40e_vsi *vsi, u16 macvlan_cnt, u16 qcnt,
>  		ch->num_queue_pairs = qcnt;
>  		if (!i40e_setup_channel(pf, vsi, ch)) {
>  			ret = -EINVAL;
> +			kfree(ch);
>  			goto err_free;
>  		}
>  		ch->parent_vsi = vsi;

Can it matter to perform the added function call before the error code assignment?

Regards,
Markus
Bowers, AndrewX Sept. 27, 2019, 7:01 p.m. UTC | #2
> -----Original Message-----
> From: Intel-wired-lan [mailto:intel-wired-lan-bounces@osuosl.org] On
> Behalf Of Navid Emamdoost
> Sent: Wednesday, September 25, 2019 8:49 AM
> Cc: netdev@vger.kernel.org; kjlu@umn.edu; linux-kernel@vger.kernel.org;
> emamd001@umn.edu; intel-wired-lan@lists.osuosl.org;
> smccaman@umn.edu; David S. Miller <davem@davemloft.net>; Navid
> Emamdoost <navid.emamdoost@gmail.com>
> Subject: [Intel-wired-lan] [PATCH] i40e: prevent memory leak in
> i40e_setup_macvlans
> 
> In i40e_setup_macvlans if i40e_setup_channel fails the allocated memory for
> ch should be released.
> 
> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> ---
>  drivers/net/ethernet/intel/i40e/i40e_main.c | 1 +
>  1 file changed, 1 insertion(+)

Tested-by: Andrew Bowers <andrewx.bowers@intel.com>

Patch
diff mbox series

diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
index 6031223eafab..7d4a14c3fe58 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_main.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
@@ -7168,6 +7168,7 @@  static int i40e_setup_macvlans(struct i40e_vsi *vsi, u16 macvlan_cnt, u16 qcnt,
 		ch->num_queue_pairs = qcnt;
 		if (!i40e_setup_channel(pf, vsi, ch)) {
 			ret = -EINVAL;
+			kfree(ch);
 			goto err_free;
 		}
 		ch->parent_vsi = vsi;