From: Jacob Keller Date: Mon, 6 Feb 2017 22:38:40 +0000 (-0800) Subject: i40e: rework exit flow of i40e_add_fdir_ethtool X-Git-Tag: v4.1.12-104.0.20170618_1145~156 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=a4edc9c8f68c66734f248a532b276e2cc7de1b09;p=users%2Fjedix%2Flinux-maple.git i40e: rework exit flow of i40e_add_fdir_ethtool Refactor the exit flow of the i40e_add_fdir_ethtool function. Move the input_label to the end of the function, removing the dependency on having a non-zero return value. Add a comment explaining why it is ok not to free the fdir data structure, because the structure is now stored in the fdir_filter_list. Change-Id: I723342181d59cd0c9f3b31140c37961ba37bb242 Signed-off-by: Jacob Keller Tested-by: Andrew Bowers Signed-off-by: Jeff Kirsher Orabug: 26132523 (cherry picked from commit 01016da1e58136518252822738fe833c662df916) Signed-off-by: Jack Vogel Reviewed-by: Brian Maly --- diff --git a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c index 10b87b822a6e..0e9330535741 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c +++ b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c @@ -2780,12 +2780,19 @@ static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi, } ret = i40e_add_del_fdir(vsi, input, true); -free_input: if (ret) - kfree(input); - else - i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL); + goto free_input; + + /* Add the input filter to the fdir_input_list, possibly replacing + * a previous filter. Do not free the input structure after adding it + * to the list as this would cause a use-after-free bug. + */ + i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL); + return 0; + +free_input: + kfree(input); return ret; }