From: Aman Singh <aman.deep.singh@intel.com>
To: dev@dpdk.org
Cc: ferruh.yigit@intel.com
Subject: [dpdk-dev] [PATCH] net/ice/base: added union to avoid ptr dereference
Date: Tue, 5 Oct 2021 16:27:06 +0530 [thread overview]
Message-ID: <20211005105706.31274-1-aman.deep.singh@intel.com> (raw)
Code changes done to avoid build issue as seen in
Bug 817 - net/ice build failure with gcc 4.8.5
error: dereferencing type-punned pointer will
break strict-aliasing rules.
Signed-off-by: Aman Singh <aman.deep.singh@intel.com>
---
drivers/net/ice/base/ice_parser_rt.c | 36 +++++++++++++++-------------
1 file changed, 20 insertions(+), 16 deletions(-)
diff --git a/drivers/net/ice/base/ice_parser_rt.c b/drivers/net/ice/base/ice_parser_rt.c
index 7a44675737..bcbc0b5e15 100644
--- a/drivers/net/ice/base/ice_parser_rt.c
+++ b/drivers/net/ice/base/ice_parser_rt.c
@@ -187,21 +187,23 @@ static u32 _bit_rev_u32(u32 v, int len)
static u32 _hv_bit_sel(struct ice_parser_rt *rt, int start, int len)
{
- u64 d64, msk;
- u8 b[8];
+ u64 msk;
+ union {
+ u64 d64;
+ u8 b[8];
+ } bit_sel;
int i;
int offset = GPR_HB_IDX + start / 16;
- ice_memcpy(b, &rt->gpr[offset], 8, ICE_NONDMA_TO_NONDMA);
+ ice_memcpy(bit_sel.b, &rt->gpr[offset], 8, ICE_NONDMA_TO_NONDMA);
for (i = 0; i < 8; i++)
- b[i] = _bit_rev_u8(b[i]);
+ bit_sel.b[i] = _bit_rev_u8(bit_sel.b[i]);
- d64 = *(u64 *)&b[0];
msk = (1ul << len) - 1;
- return _bit_rev_u32((u32)((d64 >> (start % 16)) & msk), len);
+ return _bit_rev_u32((u32)((bit_sel.d64 >> (start % 16)) & msk), len);
}
static u32 _pk_build(struct ice_parser_rt *rt, struct ice_np_keybuilder *kb)
@@ -444,21 +446,23 @@ static void _po_update(struct ice_parser_rt *rt, struct ice_alu *alu)
static u16 _reg_bit_sel(struct ice_parser_rt *rt, int reg_idx,
int start, int len)
{
- u32 d32, msk;
- u8 b[4];
- u8 v[4];
+ u32 msk;
+ union {
+ u32 d32;
+ u8 b[4];
+ } bit_sel;
- ice_memcpy(b, &rt->gpr[reg_idx + start / 16], 4, ICE_NONDMA_TO_NONDMA);
+ ice_memcpy(bit_sel.b, &rt->gpr[reg_idx + start / 16], 4,
+ ICE_NONDMA_TO_NONDMA);
- v[0] = _bit_rev_u8(b[0]);
- v[1] = _bit_rev_u8(b[1]);
- v[2] = _bit_rev_u8(b[2]);
- v[3] = _bit_rev_u8(b[3]);
+ bit_sel.b[0] = _bit_rev_u8(bit_sel.b[0]);
+ bit_sel.b[1] = _bit_rev_u8(bit_sel.b[1]);
+ bit_sel.b[2] = _bit_rev_u8(bit_sel.b[2]);
+ bit_sel.b[3] = _bit_rev_u8(bit_sel.b[3]);
- d32 = *(u32 *)&v[0];
msk = (1u << len) - 1;
- return _bit_rev_u16((u16)((d32 >> (start % 16)) & msk), len);
+ return _bit_rev_u16((u16)((bit_sel.d32 >> (start % 16)) & msk), len);
}
static void _err_add(struct ice_parser_rt *rt, int idx, bool val)
--
2.17.1
next reply other threads:[~2021-10-05 11:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-05 10:57 Aman Singh [this message]
2021-10-05 14:13 ` Ferruh Yigit
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=20211005105706.31274-1-aman.deep.singh@intel.com \
--to=aman.deep.singh@intel.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@intel.com \
/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;
as well as URLs for NNTP newsgroup(s).