提交 8ca3390b 编写于 作者: M Martyna Szapar 提交者: Yang Yingliang

i40e: Fix of memory leak and integer truncation in i40e_virtchnl.c

[ Upstream commit 24474f2709af6729b9b1da1c5e160ab62e25e3a4 ]

Fixed possible memory leak in i40e_vc_add_cloud_filter function:
cfilter is being allocated and in some error conditions
the function returns without freeing the memory.

Fix of integer truncation from u16 (type of queue_id value) to u8
when calling i40e_vc_isvalid_queue_id function.

Fixes: e284fc28 ("i40e: Add and delete cloud filter")
Signed-off-by: NMartyna Szapar <martyna.szapar@intel.com>
Signed-off-by: NJeff Kirsher <jeffrey.t.kirsher@intel.com>
Signed-off-by: NJesse Brandeburg <jesse.brandeburg@intel.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 5dec2aa8
...@@ -181,7 +181,7 @@ static inline bool i40e_vc_isvalid_vsi_id(struct i40e_vf *vf, u16 vsi_id) ...@@ -181,7 +181,7 @@ static inline bool i40e_vc_isvalid_vsi_id(struct i40e_vf *vf, u16 vsi_id)
* check for the valid queue id * check for the valid queue id
**/ **/
static inline bool i40e_vc_isvalid_queue_id(struct i40e_vf *vf, u16 vsi_id, static inline bool i40e_vc_isvalid_queue_id(struct i40e_vf *vf, u16 vsi_id,
u8 qid) u16 qid)
{ {
struct i40e_pf *pf = vf->pf; struct i40e_pf *pf = vf->pf;
struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id); struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
...@@ -3360,7 +3360,7 @@ static int i40e_vc_add_cloud_filter(struct i40e_vf *vf, u8 *msg) ...@@ -3360,7 +3360,7 @@ static int i40e_vc_add_cloud_filter(struct i40e_vf *vf, u8 *msg)
if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) { if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
aq_ret = I40E_ERR_PARAM; aq_ret = I40E_ERR_PARAM;
goto err; goto err_out;
} }
if (!vf->adq_enabled) { if (!vf->adq_enabled) {
...@@ -3368,15 +3368,15 @@ static int i40e_vc_add_cloud_filter(struct i40e_vf *vf, u8 *msg) ...@@ -3368,15 +3368,15 @@ static int i40e_vc_add_cloud_filter(struct i40e_vf *vf, u8 *msg)
"VF %d: ADq is not enabled, can't apply cloud filter\n", "VF %d: ADq is not enabled, can't apply cloud filter\n",
vf->vf_id); vf->vf_id);
aq_ret = I40E_ERR_PARAM; aq_ret = I40E_ERR_PARAM;
goto err; goto err_out;
} }
if (i40e_validate_cloud_filter(vf, vcf)) { if (i40e_validate_cloud_filter(vf, vcf)) {
dev_info(&pf->pdev->dev, dev_info(&pf->pdev->dev,
"VF %d: Invalid input/s, can't apply cloud filter\n", "VF %d: Invalid input/s, can't apply cloud filter\n",
vf->vf_id); vf->vf_id);
aq_ret = I40E_ERR_PARAM; aq_ret = I40E_ERR_PARAM;
goto err; goto err_out;
} }
cfilter = kzalloc(sizeof(*cfilter), GFP_KERNEL); cfilter = kzalloc(sizeof(*cfilter), GFP_KERNEL);
...@@ -3437,13 +3437,17 @@ static int i40e_vc_add_cloud_filter(struct i40e_vf *vf, u8 *msg) ...@@ -3437,13 +3437,17 @@ static int i40e_vc_add_cloud_filter(struct i40e_vf *vf, u8 *msg)
"VF %d: Failed to add cloud filter, err %s aq_err %s\n", "VF %d: Failed to add cloud filter, err %s aq_err %s\n",
vf->vf_id, i40e_stat_str(&pf->hw, ret), vf->vf_id, i40e_stat_str(&pf->hw, ret),
i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
goto err; goto err_free;
} }
INIT_HLIST_NODE(&cfilter->cloud_node); INIT_HLIST_NODE(&cfilter->cloud_node);
hlist_add_head(&cfilter->cloud_node, &vf->cloud_filter_list); hlist_add_head(&cfilter->cloud_node, &vf->cloud_filter_list);
/* release the pointer passing it to the collection */
cfilter = NULL;
vf->num_cloud_filters++; vf->num_cloud_filters++;
err: err_free:
kfree(cfilter);
err_out:
return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_ADD_CLOUD_FILTER, return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_ADD_CLOUD_FILTER,
aq_ret); aq_ret);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册