Commit e9a1cc2e authored by Jakob Koschel's avatar Jakob Koschel Committed by Tony Nguyen

ice: fix invalid check for empty list in ice_sched_assoc_vsi_to_agg()

The code implicitly assumes that the list iterator finds a correct
handle. If 'vsi_handle' is not found the 'old_agg_vsi_info' was
pointing to an bogus memory location. For safety a separate list
iterator variable should be used to make the != NULL check on
'old_agg_vsi_info' correct under any circumstances.

Additionally Linus proposed to avoid any use of the list iterator
variable after the loop, in the attempt to move the list iterator
variable declaration into the macro to avoid any potential misuse after
the loop. Using it in a pointer comparison after the loop is undefined
behavior and should be omitted if possible [1].

Fixes: 37c59206 ("ice: remove the VSI info from previous agg")
Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1]
Signed-off-by: default avatarJakob Koschel <jkl820.git@gmail.com>
Tested-by: Arpana Arland <arpanax.arland@intel.com> (A Contingent worker at Intel)
Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
parent 29486b6d
...@@ -2788,7 +2788,7 @@ static int ...@@ -2788,7 +2788,7 @@ static int
ice_sched_assoc_vsi_to_agg(struct ice_port_info *pi, u32 agg_id, ice_sched_assoc_vsi_to_agg(struct ice_port_info *pi, u32 agg_id,
u16 vsi_handle, unsigned long *tc_bitmap) u16 vsi_handle, unsigned long *tc_bitmap)
{ {
struct ice_sched_agg_vsi_info *agg_vsi_info, *old_agg_vsi_info = NULL; struct ice_sched_agg_vsi_info *agg_vsi_info, *iter, *old_agg_vsi_info = NULL;
struct ice_sched_agg_info *agg_info, *old_agg_info; struct ice_sched_agg_info *agg_info, *old_agg_info;
struct ice_hw *hw = pi->hw; struct ice_hw *hw = pi->hw;
int status = 0; int status = 0;
...@@ -2806,11 +2806,13 @@ ice_sched_assoc_vsi_to_agg(struct ice_port_info *pi, u32 agg_id, ...@@ -2806,11 +2806,13 @@ ice_sched_assoc_vsi_to_agg(struct ice_port_info *pi, u32 agg_id,
if (old_agg_info && old_agg_info != agg_info) { if (old_agg_info && old_agg_info != agg_info) {
struct ice_sched_agg_vsi_info *vtmp; struct ice_sched_agg_vsi_info *vtmp;
list_for_each_entry_safe(old_agg_vsi_info, vtmp, list_for_each_entry_safe(iter, vtmp,
&old_agg_info->agg_vsi_list, &old_agg_info->agg_vsi_list,
list_entry) list_entry)
if (old_agg_vsi_info->vsi_handle == vsi_handle) if (iter->vsi_handle == vsi_handle) {
old_agg_vsi_info = iter;
break; break;
}
} }
/* check if entry already exist */ /* check if entry already exist */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment