Intel-Wired-Lan Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Lobakin <alexandr.lobakin@intel.com>
To: intel-wired-lan@osuosl.org
Subject: [Intel-wired-lan] [PATCH v2 net-next 2/4] ice: switch: unobscurify bitops loop in ice_fill_adv_dummy_packet()
Date: Thu, 27 Jan 2022 16:40:07 +0100	[thread overview]
Message-ID: <20220127154009.623304-3-alexandr.lobakin@intel.com> (raw)
In-Reply-To: <20220127154009.623304-1-alexandr.lobakin@intel.com>

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>
---
 drivers/net/ethernet/intel/ice/ice_switch.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice_switch.c b/drivers/net/ethernet/intel/ice/ice_switch.c
index 7f7e929e73a8..b6b6e8f5d358 100644
--- a/drivers/net/ethernet/intel/ice/ice_switch.c
+++ b/drivers/net/ethernet/intel/ice/ice_switch.c
@@ -5266,13 +5266,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);
-- 
2.34.1


  parent reply	other threads:[~2022-01-27 15:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-27 15:40 [Intel-wired-lan] [PATCH v2 net-next 0/4] ice: switch: debloat packet templates code Alexander Lobakin
2022-01-27 15:40 ` [Intel-wired-lan] [PATCH v2 net-next 1/4] ice: switch: add and use u16[] aliases to ice_adv_lkup_elem::{h, m}_u Alexander Lobakin
2022-02-18  5:18   ` Penigalapati, Sandeep
2022-01-27 15:40 ` Alexander Lobakin [this message]
2022-02-18  5:19   ` [Intel-wired-lan] [PATCH v2 net-next 2/4] ice: switch: unobscurify bitops loop in ice_fill_adv_dummy_packet() Penigalapati, Sandeep
2022-01-27 15:40 ` [Intel-wired-lan] [PATCH v2 net-next 3/4] ice: switch: use a struct to pass packet template params Alexander Lobakin
2022-02-18  5:19   ` Penigalapati, Sandeep
2022-01-27 15:40 ` [Intel-wired-lan] [PATCH v2 net-next 4/4] ice: switch: use convenience macros to declare dummy pkt templates Alexander Lobakin
2022-02-18  5:20   ` Penigalapati, Sandeep
2022-03-14 16:30 ` [Intel-wired-lan] [PATCH v2 net-next 0/4] ice: switch: debloat packet templates code Tony Nguyen
2022-03-16 14:51   ` Alexander Lobakin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220127154009.623304-3-alexandr.lobakin@intel.com \
    --to=alexandr.lobakin@intel.com \
    --cc=intel-wired-lan@osuosl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox