From: Alexander Lobakin <alexandr.lobakin@intel.com>
To: intel-wired-lan@osuosl.org
Subject: [Intel-wired-lan] [PATCH v2 net-next 1/4] ice: switch: add and use u16[] aliases to ice_adv_lkup_elem::{h, m}_u
Date: Thu, 27 Jan 2022 16:40:06 +0100 [thread overview]
Message-ID: <20220127154009.623304-2-alexandr.lobakin@intel.com> (raw)
In-Reply-To: <20220127154009.623304-1-alexandr.lobakin@intel.com>
ice_adv_lkup_elem fields h_u and m_u are being accessed as raw u16
arrays in several places.
To reduce cast and braces burden, add permanent array-of-u16 aliases
with the same size as the `union ice_prot_hdr` itself via anonymous
unions to the actual struct declaration, and just access them
directly.
This:
- removes the need to cast the union to u16[] and then dereference
it each time -> reduces the horizon for potential bugs;
- improves -Warray-bounds coverage -- the array size is now known
at compilation time;
- addresses cppcheck complaints.
Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
---
drivers/net/ethernet/intel/ice/ice_switch.c | 15 +++++++--------
drivers/net/ethernet/intel/ice/ice_switch.h | 12 ++++++++++--
2 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/drivers/net/ethernet/intel/ice/ice_switch.c b/drivers/net/ethernet/intel/ice/ice_switch.c
index d98aa35c0337..7f7e929e73a8 100644
--- a/drivers/net/ethernet/intel/ice/ice_switch.c
+++ b/drivers/net/ethernet/intel/ice/ice_switch.c
@@ -5267,12 +5267,12 @@ ice_fill_adv_dummy_packet(struct ice_adv_lkup_elem *lkups, u16 lkups_cnt,
* over any significant packet data.
*/
for (j = 0; j < len / sizeof(u16); j++)
- if (((u16 *)&lkups[i].m_u)[j])
+ if (lkups[i].m_raw[j])
((u16 *)(pkt + offset))[j] =
(((u16 *)(pkt + offset))[j] &
- ~((u16 *)&lkups[i].m_u)[j]) |
- (((u16 *)&lkups[i].h_u)[j] &
- ((u16 *)&lkups[i].m_u)[j]);
+ ~lkups[i].m_raw[j]) |
+ (lkups[i].h_raw[j] &
+ lkups[i].m_raw[j]);
}
s_rule->pdata.lkup_tx_rx.hdr_len = cpu_to_le16(pkt_len);
@@ -5521,11 +5521,10 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
/* get # of words we need to match */
word_cnt = 0;
for (i = 0; i < lkups_cnt; i++) {
- u16 j, *ptr;
+ u16 j;
- ptr = (u16 *)&lkups[i].m_u;
- for (j = 0; j < sizeof(lkups->m_u) / sizeof(u16); j++)
- if (ptr[j] != 0)
+ for (j = 0; j < ARRAY_SIZE(lkups->m_raw); j++)
+ if (lkups[i].m_raw[j])
word_cnt++;
}
diff --git a/drivers/net/ethernet/intel/ice/ice_switch.h b/drivers/net/ethernet/intel/ice/ice_switch.h
index 7b42c51a3eb0..950a66e86227 100644
--- a/drivers/net/ethernet/intel/ice/ice_switch.h
+++ b/drivers/net/ethernet/intel/ice/ice_switch.h
@@ -129,8 +129,16 @@ struct ice_update_recipe_lkup_idx_params {
struct ice_adv_lkup_elem {
enum ice_protocol_type type;
- union ice_prot_hdr h_u; /* Header values */
- union ice_prot_hdr m_u; /* Mask of header values to match */
+ union {
+ union ice_prot_hdr h_u; /* Header values */
+ /* Used to iterate over the headers */
+ u16 h_raw[sizeof(union ice_prot_hdr) / sizeof(u16)];
+ };
+ union {
+ union ice_prot_hdr m_u; /* Mask of header values to match */
+ /* Used to iterate over header mask */
+ u16 m_raw[sizeof(union ice_prot_hdr) / sizeof(u16)];
+ };
};
struct ice_sw_act_ctrl {
--
2.34.1
next prev 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 ` Alexander Lobakin [this message]
2022-02-18 5:18 ` [Intel-wired-lan] [PATCH v2 net-next 1/4] ice: switch: add and use u16[] aliases to ice_adv_lkup_elem::{h, m}_u Penigalapati, Sandeep
2022-01-27 15:40 ` [Intel-wired-lan] [PATCH v2 net-next 2/4] ice: switch: unobscurify bitops loop in ice_fill_adv_dummy_packet() Alexander Lobakin
2022-02-18 5:19 ` 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-2-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