Skip to content

Commit 71d7816

Browse files
mszapargregkh
authored andcommitted
i40e: Fix of memory leak and integer truncation in i40e_virtchnl.c
[ Upstream commit 24474f2 ] 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: e284fc2 ("i40e: Add and delete cloud filter") Signed-off-by: Martyna Szapar <martyna.szapar@intel.com> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com> Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 48a9be9 commit 71d7816

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ static inline bool i40e_vc_isvalid_vsi_id(struct i40e_vf *vf, u16 vsi_id)
181181
* check for the valid queue id
182182
**/
183183
static inline bool i40e_vc_isvalid_queue_id(struct i40e_vf *vf, u16 vsi_id,
184-
u8 qid)
184+
u16 qid)
185185
{
186186
struct i40e_pf *pf = vf->pf;
187187
struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
@@ -3345,23 +3345,23 @@ static int i40e_vc_add_cloud_filter(struct i40e_vf *vf, u8 *msg)
33453345

33463346
if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
33473347
aq_ret = I40E_ERR_PARAM;
3348-
goto err;
3348+
goto err_out;
33493349
}
33503350

33513351
if (!vf->adq_enabled) {
33523352
dev_info(&pf->pdev->dev,
33533353
"VF %d: ADq is not enabled, can't apply cloud filter\n",
33543354
vf->vf_id);
33553355
aq_ret = I40E_ERR_PARAM;
3356-
goto err;
3356+
goto err_out;
33573357
}
33583358

33593359
if (i40e_validate_cloud_filter(vf, vcf)) {
33603360
dev_info(&pf->pdev->dev,
33613361
"VF %d: Invalid input/s, can't apply cloud filter\n",
33623362
vf->vf_id);
3363-
aq_ret = I40E_ERR_PARAM;
3364-
goto err;
3363+
aq_ret = I40E_ERR_PARAM;
3364+
goto err_out;
33653365
}
33663366

33673367
cfilter = kzalloc(sizeof(*cfilter), GFP_KERNEL);
@@ -3422,13 +3422,17 @@ static int i40e_vc_add_cloud_filter(struct i40e_vf *vf, u8 *msg)
34223422
"VF %d: Failed to add cloud filter, err %s aq_err %s\n",
34233423
vf->vf_id, i40e_stat_str(&pf->hw, ret),
34243424
i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
3425-
goto err;
3425+
goto err_free;
34263426
}
34273427

34283428
INIT_HLIST_NODE(&cfilter->cloud_node);
34293429
hlist_add_head(&cfilter->cloud_node, &vf->cloud_filter_list);
3430+
/* release the pointer passing it to the collection */
3431+
cfilter = NULL;
34303432
vf->num_cloud_filters++;
3431-
err:
3433+
err_free:
3434+
kfree(cfilter);
3435+
err_out:
34323436
return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_ADD_CLOUD_FILTER,
34333437
aq_ret);
34343438
}

0 commit comments

Comments
 (0)