Skip to content

Commit

Permalink
ice: switch: unobscurify bitops loop in ice_fill_adv_dummy_packet()
Browse files Browse the repository at this point in the history
A loop performing header modification according to the provided mask
in ice_fill_adv_dummy_packet() is very cryptic (and error-prone).
Replace two identical cast-deferences with a variable. Replace three
struct-member-array-accesses with a variable. Invert the condition,
reduce the indentation by one -> eliminate line wraps.

Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
Tested-by: Marcin Szycik <marcin.szycik@linux.intel.com>
Tested-by: Sandeep Penigalapati <sandeep.penigalapati@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
  • Loading branch information
Alexander Lobakin authored and Tony Nguyen committed Apr 7, 2022
1 parent 135a161 commit 27ffa27
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions drivers/net/ethernet/intel/ice/ice_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -5810,13 +5810,15 @@ ice_fill_adv_dummy_packet(struct ice_adv_lkup_elem *lkups, u16 lkups_cnt,
* indicated by the mask to make sure we don't improperly write
* over any significant packet data.
*/
for (j = 0; j < len / sizeof(u16); j++)
if (lkups[i].m_raw[j])
((u16 *)(pkt + offset))[j] =
(((u16 *)(pkt + offset))[j] &
~lkups[i].m_raw[j]) |
(lkups[i].h_raw[j] &
lkups[i].m_raw[j]);
for (j = 0; j < len / sizeof(u16); j++) {
u16 *ptr = (u16 *)(pkt + offset);
u16 mask = lkups[i].m_raw[j];

if (!mask)
continue;

ptr[j] = (ptr[j] & ~mask) | (lkups[i].h_raw[j] & mask);
}
}

s_rule->pdata.lkup_tx_rx.hdr_len = cpu_to_le16(pkt_len);
Expand Down

0 comments on commit 27ffa27

Please sign in to comment.